123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- ;file: coldet.s
- ;collision detect
- ;sister file: cdvars.s (collision detect variables)
- ;
- ; precision version
- ; call with movs in x and y regs
- ; rts carry set if collision
- ;
- coldet:
- pushx
- pushy
- ;
- ; calc useful params
- ;
- lda movy,x ;xd = movy,x
- sta xd
- lda movht,x ;xu = (movht,x * 16) + xd
- asl
- asl
- asl
- asl
- clc
- adc xd
- sta xu
- lda movy,y ;yd = movy,y
- sta yd
- lda movht,y ;yu = (movht,y * 16) + yx
- asl
- asl
- asl
- asl
- clc
- adc yd
- sta yu
- lda movx,x ;xl = movx,x
- clc
- adc #($100 - SCWP)/2
- sta xl
- lda movx,y ;yl = movx,y
- clc
- adc #($100 - SCWP)/2
- sta yl
- lda movw,x ;xr = xl + (movw,x << 2)
- asl
- asl
- clc
- adc xl
- sta xr
- lda movw,y ;yr = yl + (movw,y << 2)
- asl
- asl
- clc
- adc yl
- sta yr
- ;
- ; find lesser of xu,yu store as lesserup
- ;
- lda xu
- cmp yu
- bcc .yuOVERxu
- ;xuOVERyu:
- lda yu
- jmp .break1
- .yuOVERxu:
- lda xu
- .break1:
- sta lesserup
- ;
- ; switch on greater of (xd,yd)
- ;
- lda xd
- cmp yd
- bcc .ydOVERxd
- ;
- ; set high addresses and height of overlap
- ;
- ;xdOVERyd:
- lda movfrh,x ;xah = movfrh,x
- sta xah
- lda movfrh,y ;yah = movfrh,y + (xd - yd)
- clc
- adc xd
- sec
- sbc yd
- sta yah
- lda xd ;cdheight = xd - lesser(xu,yu) (2's comp)
- sec
- sbc lesserup
- sta cdheight
- jmp .break2
- .ydOVERxd:
- lda movfrh,y ;yah = movfrh,y
- sta yah
- lda movfrh,x ;xah = movfrh,x + (yd - xd)
- clc
- adc yd
- sec
- sbc xd
- sta xah
- lda yd ;cdheight = yd - lesser(xu,yu) (2's comp)
- sec
- sbc lesserup
- sta cdheight
- .break2:
- ;
- ; 2`s comp of height and its carry are ready here
- ; if carry set, then no overlap, ret false
- ;
- bcc .lineoverlap
- jmp .exitfalse
- .lineoverlap:
- ;
- ; find lesser of xr,yr store as lesserright
- ;
- lda xr
- cmp yr
- bcc .yrOVERxr
- ;xrOVERyr:
- lda yr
- jmp .break3
- .yrOVERxr:
- lda xr
- .break3:
- sta lesserright
- ;
- ; switch on greater of (xl,yl)
- ;
- lda xl
- cmp yl
- bcc .yprimary
- ;
- ; set low addresses and width of overlap
- ;
- ;xprimary:
- lda xah ;pah = xah
- sta pah
- lda yah ;sah = yah
- sta sah
- lda movfrl,x ;pal = movfrl,x
- sta pal
- lda xl ;pshift = (xl - yl) & %11
- sec
- sbc yl
- sta i ;save this intermediate calc (xl - yl)
- and #%11
- sta pshift
- eor #%11 ;sshift = ~pshift + 1 & %11
- clc
- adc #1
- sta sshift
- lda i ;sal = ((xl - yl) >> 2) + movfrl,y
- lsr
- lsr
- clc
- adc movfrl,y
- sta sal
- lda xl ;cdwidth = xl - lesser(xr,yr) (2's comp)
- sec
- sbc lesserright
- sta cdwidth
- jmp .break4
- .yprimary:
- lda yah ;pah = yah
- sta pah
- lda xah ;sah = xah
- sta sah
- lda movfrl,y ;pal = movfrl,y
- sta pal
- lda yl ;pshift = (yl - xl) & %11
- sec
- sbc xl
- sta i ;save this intermediate calc (yl - xl)
- and #%11
- sta pshift
- eor #%11 ;sshift = ~pshift + 1 & %11
- clc
- adc #1
- sta sshift
- lda i ;sal = ((yl - xl) >> 2) + movfrl,x
- lsr
- lsr
- clc
- adc movfrl,x
- sta sal
- lda yl ;cdwidth = yl - lesser(yr,xr) (2's comp)
- sec
- sbc lesserright
- sta cdwidth
- .break4:
- ;
- ; 2`s comp of width and its carry are ready here
- ; carry set, then no overlap, rts false
- ;
- bcc .pixoverlap
- jmp .exitfalse
- .pixoverlap:
- ;
- ; x and y regs now used for new purposes
- ;
- ldy #0
- ;
- ; save vars that will be clobbered in inner loop but needed again
- lda pal
- sta palsav
- lda sal
- sta salsav
- .lineloop:
- lda (sal),y ;get first secondary byte
- beq .skipc1
- .if 0
- jsr convbits
- .endif
- tax ;convert 2bits per pixel to 1
- lda COLTAB,x
- .skipc1:
- inc sal ;point to next byte
- sta sbyte
- lda cdwidth ;init remaining width
- sta rwidth
- .pixloop:
- lda (pal),y ;get primary byte
- beq .skipc2
- .if 0
- jsr convbits ;convert 2bits per pixel to 1
- .endif
- tax
- lda COLTAB,x
- .skipc2:
- inc pal ;point to next byte
- sta pbyte
- ldx pshift ;shift primary byte
- beq .donepshift
- .pshiftloop:
- lsr
- dex
- bne .pshiftloop
- .donepshift:
- and sbyte ;AND shifted primary with secondary bytes
- bne .exittrue
- lda rwidth ;update remaining width, exit inner if zero
- clc
- adc sshift
- sta rwidth
- beq .breakinner
- ;
- ; Get secondary byte, inc pointer, shift, AND with primary byte
- ;
- lda (sal),y
- beq .skipc3
- .if 0
- jsr convbits
- .endif
- tax ;convert 2 bits per pixel to 1
- lda COLTAB,x
- .skipc3:
- inc sal
- sta sbyte
-
- ldx sshift ;shift secondary byte
- beq .donesshift
- .sshiftloop:
- lsr
- dex
- bne .sshiftloop
- .donesshift:
- and pbyte ;AND shifted secondary with primary
- bne .exittrue
- lda rwidth ;update remaining width, exit inner if zero
- clc
- adc pshift
- sta rwidth
- beq .breakinner
- jmp .pixloop
- .breakinner:
- ;
- ; if no remaining height, exit false
- ;
- inc cdheight
- beq .exitfalse
- ;
- ; restore clobbered vars, check next line
- ;
- lda palsav
- sta pal
- lda salsav
- sta sal
- inc pah ;inc address highs
- inc sah
- jmp .lineloop
- .exittrue:
- popy
- popx
- sec
- rts
- .exitfalse:
- popy
- popx
- clc
- rts
- ;
- ; convert bits
- ; compresses one byte of 2 bits per pixel to one bit per pixel
- ; input and output in accumulator
- ; clobbers x reg, i
- .if 0
- convbits:
- tax
- lda COLTAB,x
- rts
- tax
- lda #0
- sta i
- txa
- and #%11
- beq .skip1
- lda #1
- sta i
- .skip1: txa
- and #%1100
- beq .skip2
- lda #%10
- ora i
- sta i
- .skip2: txa
- and #%110000
- beq .skip3
- lda #%100
- ora i
- sta i
- .skip3: txa
- and #%11000000
- beq .skip4
- lda #%1000
- ora i
- sta i
- .skip4: lda i
- .endif
- rts
- ;
- ; set score to an absolute number, in A reg (octal readout)
- ;
- .if 0
- setscore:
- sta i
- pushx
- pushy
- lda #0
- sta score
- sta score+1
- sta score+2
- lda i
- asl
- asl
- asl
- asl
- and #%01110000
- jsr incsc
- lda i
- asl
- and #%01110000
- ora #1
- jsr incsc
- lda i
- lsr
- lsr
- and #%01110000
- ora #2
- jsr incsc
- popy
- popx
- lda i
- rts
- .endif
|