Autore Topic: Screen Filler  (Letto 1800 volte)

Tremal-Naik

  • Neo-iscritto
  • *
  • Post: 21
  • Gioco Preferito: Turrican
Screen Filler
« il: 11 Maggio 2005, 11:46:50 »
 Ecco qui! Dopo un paio d'ore di lavoro e' nata la mia routine di riempimento dello schermo in modalita' bitmap. Il riempimento avviene pixel dopo pixel da sinistra a destra dal pixel in alto a destra fino a quello in basso a sinistra.

PS: scusate l'inglese maccheronico dei commenti  :P

Codice: [Seleziona]
; * Screen filler
; * Written by Massimiliano Benini (aka Tremal-Naik)
; * E-mail: camionsauro@despammed.com
; *
; * 11/05/2005
; *
; * A routine to fill the screen pixel after pixel
; * from left to right in bitmapped mode

    
    *=$0900
    !to "..\binary\screenfiller"
    
TABLE_POINTER = $06
BACKUP_BASE_ADDRESS = $04
FILLER = $07
CHAR_COUNT = $08
ROW_COUNT = $09
BASE_ADDRESS = $02
    
    lda #$00
    sta TABLE_POINTER
    sta FILLER
    sta CHAR_COUNT
    sta ROW_COUNT
    sta BASE_ADDRESS
    sta BACKUP_BASE_ADDRESS
    ldx TABLE_POINTER
    lda MSB_base_address,x
    sta BASE_ADDRESS+1
    sta BACKUP_BASE_ADDRESS+1
    
    ldx #$00
clear_screen
    lda #$10
    sta $0400,x
    sta $0500,x
    sta $0600,x
    sta $06e8,x
    lda #$00
    inx
    bne clear_screen
    
    lda $d011
    ora #%00100000
    sta $d011          ; Bitmap hires mode
    
    lda #$18
    sta $d018          ; Bitmap in $2000
    
    sei
    lda #%01111111
    sta $dc0d          ; No CIA interrupt
    lda #$01
    sta $d01a          ; Allow raster interrupt
    lda #<fill_routine
    sta $0314
    lda #>fill_routine
    sta $0315
    lda #$fa
    sta $d012
    cli

wait
    lda TABLE_POINTER
    cmp #25
    bne wait
    
    sei
    lda #$31
    sta $0314
    lda #$ea
    sta $0315          ; Default IRQ vector
    lda #$00
    sta $d01a          ; No raster IRQ
    lda #%11111111
    sta $dc0d          ; Enable CIA
    lda #$15
    sta $d018          ; Default charset
    lda $d011
    and #%11011111
    sta $d011          ; Normal character mode
   ;jsr $ff5b         ; Alternative to the previous lines
   ;jsr $fd15
   ;jsr $ff84
    cli
    
    jsr $e544          ; Clear screen
    
    rts
        
  
    
fill_routine
    lda $d019
    sta $d019          ; ACK raster interrupt
    sec
    ror FILLER
    lda FILLER
    sta (BASE_ADDRESS),y; Fill 8 bit in sequence
    cmp #$ff
    bne continue_to_fill
    
   ; After filling 8 bit skip to the next char
   ; or the next pixel row (after 40*8 pixel)
   ; or the next character row
    
    inc CHAR_COUNT
    lda CHAR_COUNT
    cmp #40
    bne no_new_line
    
   ; After filling a complete pixel line restore
   ; the base address of the line and add $01 to
   ; point at the next line
    
    inc ROW_COUNT
    lda BACKUP_BASE_ADDRESS
    clc
    adc #$01
    sta BASE_ADDRESS
    sta BACKUP_BASE_ADDRESS
    lda BACKUP_BASE_ADDRESS+1
    sta BASE_ADDRESS+1
    sta BACKUP_BASE_ADDRESS+1
    lda #$00
    sta CHAR_COUNT
    
   ; Have I filled 8 line?
    
    lda ROW_COUNT
    cmp #$08
    bne continue_to_fill
    
   ; If so point $140 byte onward reading the MSB
   ; from the table and adding $38 ($40-$08 because
   ; $08 is yet added in the next lines) to the LSB.
    
    lda #$00
    sta ROW_COUNT
    inc TABLE_POINTER
    ldx TABLE_POINTER
    lda MSB_base_address,x
    sta BASE_ADDRESS+1
    sta BACKUP_BASE_ADDRESS+1
    lda BACKUP_BASE_ADDRESS
    clc
    adc #$38
    sta BASE_ADDRESS
    sta BACKUP_BASE_ADDRESS
    jmp continue_to_fill
    
   ; Fill the next 8 bit
    
no_new_line
    lda BASE_ADDRESS
    clc
    adc #$08
    sta BASE_ADDRESS
    bcc no_carry
    inc BASE_ADDRESS+1
no_carry
    lda #$00
    sta FILLER
    
continue_to_fill
    pla
    pla
    pla
    rti
    
   ; Base address of first character
   ; of the actual line
    
MSB_base_address                    
    !byte $20, $21, $22, $23, $25, $26, $27
    !byte $28, $2a, $2b, $2c, $2d, $2f
    !byte $30, $31, $32, $34, $35, $36, $37
    !byte $39, $3a, $3b, $3c, $3e, $3f
    
    *=$2000
    !fi 8000, $00