| |
Trap
Registered: Jul 2010 Posts: 223 |
Bank switching with fastloaders
Hi,
I've decided that I want to use Spindle for my little project, but I can't seem to get this bank switching done right.
So, normally we bank switch using DD00, but as I read from the documentation (and pretty much everywhere else when fastloaders are mentioned) we should use DD02 for switching instead.
Now, if I just do
lda #$3d
sta $dd02
that should switch the VIC to bank 1 ($4000-$7fff) right? (according to the spindle docs anyway) but that just doesn't happen.
The topic on this over on Codebase uses DD00 too. Looking at the memory map DD02 is 'Data Direction Register' and has absolutely nothing to do with VIC bank select. I'm confused. What am I missing here?
Thanks.
/Trap |
|
| |
Peiselulli
Registered: Oct 2006 Posts: 81 |
Have a look at this example (ACME syntax)
!cpu 6510
!to "switch.prg",cbm
* = $0801
!byte $0b,$08,$01,$00,$9e,$32,$30,$36,$31,0,0,0
sei
lda #$03
ldx #$00
stx $dd00
l1: sax $dd02
ldy #$20
l2: bit $d011
bpl l2
l3: bit $d011
bmi l3
dey
bne l2
inx
jmp l1
|
| |
Trap
Registered: Jul 2010 Posts: 223 |
erhm, that example also uses DD00. Didn't make me any less confused :) |
| |
Stone
Registered: Oct 2006 Posts: 172 |
I never knew about this trick. Pretty cool! I would guess that it only works with the bank selection bits of $dd00 set to 0 and that clearing a bit in $dd02 would cause the VIC chip to read a 1 from the corresponding bit in the bank selection register, otherwise the value from $dd00 is used. |
| |
Peiselulli
Registered: Oct 2006 Posts: 81 |
Quote:erhm, that example also uses DD00. Didn't make me any less confused :)
But only in the initialization before the loop. |
| |
Copyfault
Registered: Dec 2001 Posts: 478 |
The "trick" is also used in several FLI-routines. It confused me, too, when I tried it for the first time.
To understand it, one has to know that 1. the vic bank bits of DD00 are low active and 2. the vic bank bits are "masked" depending on the corresponding data direction register DD02.
The "masking" works as already stated by Stein. Only the vic bits with a set mask bit in DD02 gets through. A cleared mask bit fixes the resulting bank selection bit to '1'.
If we want to know the no.of the selected vic bank, we have to take the "low activity" of the bank bits into account. This can be summarized e.g.with the following formula:
vic bank no. = (DD00 eor #$03) and DD02
Setting DD00:=0, the formula gives vic bank no.=DD02, so using DD02 for bank switching has the nice side effect that we can directly put the wanted vic bank no.into a reg and don't have to f**k around with any complements.
The following table shows all possible combinations of DD00/DD02 and the resulting vic bank selected.
DD00 00 01 10 11
DD02
00 0 0 0 0
01 1 0 1 0
10 2 2 0 0
11 3 2 1 0
Hope this helps to get rid of the confusion;) |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
I have met with this one when having trouble displaying interlaced pics with Krill's loader, however using this resulted in the same buggy loading instead of fixing it, so I like to think that this "trick" is essentially the same as setting dd00. |
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
obviously you need to store the proper values so the other bits dont change =P |
| |
Frantic
Registered: Mar 2003 Posts: 1648 |
If someone wants to write something brief about this dd00/dd02 thing for codebase, please go ahead and do so. I think it would be useful. |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
obviously you're trolling again. I wonder if you are aware of what you are doing. Its a sign of low self esteem, continously trying to proove everyone is an idiot (but you) |
| |
Mixer
Registered: Apr 2008 Posts: 452 |
Didn't Krills loader have an option to put it in a mode so that it does not bother $dd00 writes? This was in some earlier Forum discussion about the subject.
There is a similar thing in the Poor/Bias Crusher fix loader. It sends a commmand to drive to put the drive code into a loop so that one do bank switching with 00 01 02 03 to $dd00 and 0 in the high bits does not bother the drive.
Drive code loop is waiting for specific value written to high bits of $dd00 and once it is received the drive code moves back to basic receiving loop.
Obviously that does not work if bank switching is needed while loading. For that one needs $dd02 or a loader that does lda bits OR #bank sta $dd00 or similar when transfering data.
Anyway, a good feature. |
| |
doynax Account closed
Registered: Oct 2004 Posts: 212 |
Off-topic but the same "trick" of relying on the pull-up in input mode applies other NMOS logic as well.
Another application is for controlling the memory configuration through either $00 or $01, thereby allowing the I/O page to be cheaply swapped in and restored from within an interrupt handler regardless of the previous configuration.
E.g.: lda #%00101111 ;One-time initialization
sta $00
lda #%00110101
sta $01
;Main-line code
dec $01 ;Swap out the I/O page
.
.
inc $01 ;Restore the I/O page
interrupt: inc $00 ;Force in the I/O page
.
.
dec $00 ;Restore previous configuration
rti
|
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
Quote:I wonder if you are aware of what you are doing.
i am asking that myself every time you post into a coding thread :)
doynax: thats a nice application of this "trick" indeed... saving a zeropage location and a cycle <3 |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
Quote: Didn't Krills loader have an option to put it in a mode so that it does not bother $dd00 writes? This was in some earlier Forum discussion about the subject.
There is a similar thing in the Poor/Bias Crusher fix loader. It sends a commmand to drive to put the drive code into a loop so that one do bank switching with 00 01 02 03 to $dd00 and 0 in the high bits does not bother the drive.
Drive code loop is waiting for specific value written to high bits of $dd00 and once it is received the drive code moves back to basic receiving loop.
Obviously that does not work if bank switching is needed while loading. For that one needs $dd02 or a loader that does lda bits OR #bank sta $dd00 or similar when transfering data.
Anyway, a good feature.
Krill's dd00 ignoring is for routines when you are doing stuff like sta d018 sta dd00 in the raster, so the loader in the drive will not listen as long the raster fx is going. It's the chessboard fx in soiled legacy that needed it :) |
| |
Trap
Registered: Jul 2010 Posts: 223 |
thank you. I've played around with it and finally understood it.
Now, what are the 'rules' for dd00 when using fastloaders? I mean, should I initialize dd00 with AND #%11111100 when the demo starts and then only use dd02 for all code following that? Can I still use dd00 as long as I am not actively loading anything?
/Trap |
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
when not loading, it should be enough to set the other (IEC related) bits to input to not disturb the loader. and setup them properly before loading again, ofcourse :) that part is usually handled by the loader though - the problem usually only arises when trying to do bankswitching while loading. |
| |
lft
Registered: Jul 2007 Posts: 369 |
For spindle, there is no need to initialise dd00, as this is taken care of by the bootloader. So you only ever need to touch dd02.
Perhaps you are developing an effect as a standalone program, and launch it directly without spindle. In that case, you should initialise dd00 to 0.
Writing zero to dd00 is safe between calls to spindle, so there shouldn't be any problem if you forget to remove the initialisation code later. |
| |
Trap
Registered: Jul 2010 Posts: 223 |
Great. Thank you.
Back to coding ;)
br
Trap |
| |
Krill
Registered: Apr 2002 Posts: 2980 |
Quoting OswaldKrill's dd00 ignoring is for routines when you are doing stuff like sta d018 sta dd00 in the raster, so the loader in the drive will not listen as long the raster fx is going. It's the chessboard fx in soiled legacy that needed it :) That was an older loader which didn't, as groepaz suggested, simply set all outgoing bits to input when idle, so that the $dd00 value would be irrelevant. That special "bus lock" thing isn't needed with the current one, and i went in the other direction than lft did with Spindle: you can set $dd00 normally while loading (values 0..3 only, and no masking), while the loader sets $dd02. |