* = $033C ;GRAPHICS 1 ;25/08/2025 ; ; ;--------------------------------- ;Enter/exit hires subroutine ; ;hires memory: fm $2000 to $3F3F ; (fm 8192 to 16191) ;col/scrn mem: fm $0400 to $07E7 ; (fm 1024 to 2023) ; ;Entry point to enter hires ; LDA $D011 ;Set bit 5 of $D011 ORA #$20 ;w/logic OR %00100000. PHA ; LDA $D018 ;Set bit 3 of $D018 ORA #$08 ;w/logic OR %00001000. ; BNE L1 ;goto L1 (always, ;given that A!=0) ; ;Entry point to exit hires ; LDA $D011 ;Reset bit 5 of $D011 AND #$DF ;w/AND mask %11011111 PHA ; LDA $D018 ;Reset bit 3 of $D018 AND #$F7 ;w/AND mask %11110111. ; ;Common part of the routine ; L1: STA $D018 ;set the VIC II PLA ;registers STA $D011 ; RTS ;Return to caller. ; ; ; ;--------------------------------- ;Fill screen memory subroutine ; ;hires memory: fm $2000 to $3F3F ; (fm 8192 to 16191) ;color memory: fm $0400 to $07E7 ; (fm 1024 to 2023) ; ;Set fill val in loc $FD (dec 253) ; ; ;Entry point to fill hires screen ; ;Set the following ;constants: LDY #$20 ;ptr val (MSB) Y=20h, LDX #$1F ;blocks to fill X=1Fh, LDA #$40 ;plus extra A=3Fh loc. ; BNE L2 ;goto L2 (always, ;given that A!=0) ; ; ;Entry point to fill color memory ; ;Set the following ;constants: LDY #$04 ;ptr val (MSB) Y=04h, LDX #$03 ;blocks to fill X=03h, LDA #$E8 ;plus extra A=E7h loc. ; ; L2: STA $02 ;Save extra loc A ;into $02. ; ;Common part of the fill routine ; STY $FC ;Set ptr (MSB) to Y. LDY #$00 ;Ptr val (LSB) Y=0. STY $FB ;Set ptr (LSB) to Y. ; LDA $FD ;Read fill val fm $FD. ; L3: DEY ;Fill a blk (FFh loc). STA ($FB),Y ; BNE L3 ; ; INC $FC ;Next block. DEX ; BNE L3 ; ; LDY $02 ;Recover extra loc ;from $02 ; L4: DEY ;fill extra locations. STA ($FB),Y ; BNE L4 ; ; RTS ;Return to caller. ; ; ; ;--------------------------------- ;plot x,y subroutine ;(without lookup tables) ; ;set x val in loc $FD (dec 253) ;and y val in loc $FE (dec 254) ;valid ranges 0<=x<=255, 0<=y<=199 ; CLD ;calcs in binary mode ; ;Calculate the base address of ptr ; LDY $FE ;load y value from $FE ; ;First of all let's ;calc the ads of ;first cell of the row. TYA ;Transfer y val in A ;for later use. ; AND #$F8 ;Perform an AND mask ;to obtain the number ;of the row multiplied ;by 8. ; ;Now divide by 8 ;in three steps ;and then set the most ;significant bit to 1: ; LSR ;first divide by 2 STA $02 ;and store in $02 ;for later calcs... LSR ;...then divide by 2 SEC ;and then divide ROR ;by 2 again setting ;the leftmost bit ;of A to 1. ; ;Now we have in the ;rightmost 5 bits ;of A ;the number of the ;row (0-24), and ;the leftmost bit ;of A is =1. ; ADC $02 ;Now add the value ;previously saved ;in $02. ;Carry is already=0 ;thanks to the last ;ROR operation. ; ;This gives ;an 8 bit number ;composed as follows: ;The leftmost 6 bits ;are the MSB of ptr, ;the rightmost 2 bits ;are the LSB of ptr. ; TAX ;Save the number in X ;for later use. ; LSR ;Right shift the LSR ;number two times: ;now we have in A ;the MSB of the ptr. ; STA $FC ;Set the ptr (MSB). ; TXA ;Recover the number ;from X. ; ROR ;Rotate right it ROR ;3 times through ROR ;carry and AND #$C0 ;reset bits 0 to 5: ;now we have in A ;the LSB of the ptr. ; STA $FB ;Set the ptr (LSB) ; ;Now we have in ptr ;the ads of the first ;cell of the row. ; ;Calculate the index ; LDX $FD ;Load x val from $FD, TXA ;copy it in A, AND #$F8 ;perform an AND mask ;to obtain col offset STA $02 ;and save it in $02 ;for later use. ; TYA ;Load y value in A, AND #$07 ;perform an AND mask ;to obtain row offset, ORA $02 ;add col offset to ;obtain index and TAY ;save index into Y. ; ;Calculate the value to perform ;the OR mask to set the bit ; TXA ;Recover x val fm X, AND #$07 ;perform an AND mask ;to obtain bit pos TAX ;and save it into X. ; LDA #$00 ;Set A=0 ; SEC ;Set in carry value 1 ;to be shifted INX ;and inc by 1 the ;cycle counter. ; L5: ROR ;Right shift the '1' DEX ;in A until X=0. BNE L5 ;This give the mask ;to perform the OR ;in the actual cell. ; ;Set the bit ; ORA ($FB),Y ;Set the bit in the STA ($FB),Y ;actual cell. ; RTS ;Return to caller. .END