Hi all, some help would be appreciated.
To get back into assembler I'm trying to code some routines to display hexagonal maps in mode2. It's coming along nicely but I can't figure out this behavior.
The following routine (with some data parts left out) displays a hexagonal sprite at one of 149 screen positions which are arranged in an hexagonal grid.
Due to the EOR it nicely removes the hex again when calling it for the second time. This way it displays a the map defined from 1510 onwards.
To speed up things I want to move the map drawing to assembler as well. As a first test to see how fast that would be I made the test loop at line 1320, which I presumed to have the same sort of behaviour. However, somehow the sprite reference seems to get mixed up in this case (see screenshot)
So can anybody tell what the USR at 1480 call is doing to make everything (seemingly) correct? I'm not using any stack now so I presume I don't have to save registers as usual.
Code:
>LIST
10MODE2
20REMVDU28,16,31,19,0
30DIMMC% &500
40FORopt%=0TO2STEP2
50P%=MC%
60[
70OPT opt%
80.hexer ROL A:STA hexnr
90 TXA:CLC:ROL A:TAX:BCCloscr
100 \Carry is set, so use hscreen position
110.hiscr LDA hscreen,X:STA &81:INX:LDA hscreen,X:STA&80:JMPldspr
120.loscr LDA screen,X:STA &81:INX:LDA screen,X:STA&80
130.ldspr LDX hexnr:LDA spstrt,X:STA &82:INX:LDA spstrt,X:STA&83
140:
150.main \Loop for 6 rows
160 LDA#&06
170 STA &84
180.row \Loop for 6 bloc4s
190 LDX #&06
200.blk LDY #&00
210 LDA (&82),Y:EOR (&80),Y:STA (&80),Y:INY
220 LDA (&82),Y:EOR (&80),Y:STA (&80),Y:INY
230 LDA (&82),Y:EOR (&80),Y:STA (&80),Y:INY
240 LDA (&82),Y:EOR (&80),Y:STA (&80),Y
250 \Increase screen base address by 8 (skip 4 bytes)
260 CLC:LDA #&08:ADC &80:STA &80:BCC spradd
270 LDA #&00:ADC &81:STA &81
280 \Increase sprite base address by 4
290.spradd CLC:LDA #&04:ADC &82:STA &82:BCC nxtblk
300 LDA #&00:ADC &83:STA &83
310.nxtblk DEX:BNE blk
320 \Check last nibble of screen address
330 LDA &80:AND #&0F:CMP #&0C:BEQ fulrow
340 LDA &80:AND #&0F:CMP #&04:BEQ fulrow
350 \Nibble=0 or 8, so substract &2C
360 SEC:LDA &80:SBC #&2C:STA &80:BCS nxtrow
370 LDA &81:SBC #&00:STA &81
380 JMP nxtrow
390.fulrow CLC:LDA #&4C:ADC &80:STA &80:LDA #&02:ADC &81:STA &81
400.nxtrow DEC &84:BNE row
410 RTS
420:
430.spstrt
440EQUW water:EQUW plains:EQUW hills:EQUW desert:EQUW city
450.hexnr EQUB &00 \Hex to be plotted
460:
470\6 rows of 6 blocks of 4 bytes top to bottom
480\block is 4 bytes bottom to top
490.plains
500EQUD&00000000:EQUD&0C040400:EQUD&0C0C0C00
510EQUD&0C0C0400:EQUD&0C080800:EQUD&00000000
520EQUD&04040000:EQUD&0C0C0C08:EQUD&0C0C0C0C
530EQUD&0C0C080C:EQUD&0C0C0C0C:EQUD&08080000
540EQUD&0C0C0C04:EQUD&0C0C0C04:EQUD&0C080C0C
550EQUD&0C0C0C0C:EQUD&0C0C080C:EQUD&0C0C0C08
560EQUD&040C0C0C:EQUD&0C0C080C:EQUD&0C0C0C0C
570EQUD&0C040C0C:EQUD&0C0C080C:EQUD&080C0C0C
580EQUD&00000404:EQUD&0C080C0C:EQUD&0C0C0C0C
590EQUD&0C0C0C0C:EQUD&0C0C0C0C:EQUD&00000808
600EQUD&00000000:EQUD&0004040C:EQUD&00040C0C
610EQUD&000C0C08:EQUD&0008080C:EQUD&00000000
620.water
<SNIP>
750.hills
<SNIP>
880.city
<SNIP>
1010.desert
<SNIP>
1140.screen \vertical rows of 10 hexes
1150EQUD&80370030:EQUD&8046003F:EQUD&8055004E:EQUD&8064005D:EQUD&8073006C
<SNIP>
1280.hscreen
1290EQUD&6075E06D
1300EQUD&0C3C8C34:EQUD&0C4B8C43:EQUD&0C5A8C52:EQUD&0C698C61:EQUD&0C788C70
1310EQUD&B0393032:EQUD&B0483041:EQUD&B0573050:EQUD&B066305F:EQUD&B075306E
1311:
1320.test LDA#100:STA&85
1330.dal LDA#1:LDX&85:JSRhexer:DEC&85:BNEdal:RTS
1340]
1350NEXTopt%
1360CLS
1370DIMMAP%(10,15)
1380FORY%=0TO9:FORX%=0TO14:READ MAP%(Y%,X%):NEXTX%:NEXTY%
1390FORY%=0TO9:FORX%=0TO14:I%=X%*10+Y%:PROChex(I%,MAP%(Y%,X%)):NEXTX%:NEXTY%
1400REMFORi%=0TO149:PROChex(i%,0):NEXTi%
1410REMCALL(test)
1420:
1430END
1440:
1450DEFPROChex(pos%,type%)
1460LOCALA%,X%,Y%,R%,C%
1470A%=type%:X%=pos%:Y%=0
1480R%=USR(hexer)
1490ENDPROC
1500:
1510DATA 0,0,0,0,1,1,1,1,2,2,2,2,1,1,1
1520DATA 0,0,0,0,0,1,1,2,2,2,3,3,1,2,3
1530DATA 0,0,0,0,0,0,1,1,2,2,2,3,1,2,3
1540DATA 1,0,0,0,0,0,0,1,1,2,2,2,1,2,3
1550DATA 1,0,0,0,0,0,0,1,1,4,4,2,2,2,2
1560DATA 1,1,1,0,0,0,0,0,1,1,4,4,1,2,2
1570DATA 2,1,1,1,1,0,0,0,1,1,4,1,1,1,2
1580DATA 2,2,1,1,1,1,1,0,1,1,1,0,0,0,2
1590DATA 3,2,2,2,1,1,1,1,0,1,1,0,0,2,2
1600DATA 3,3,2,2,2,1,2,1,0,1,0,1,0,0,2
>