Skip to content

Instantly share code, notes, and snippets.

@cbmeeks
Created November 29, 2013 06:10
Show Gist options
  • Save cbmeeks/7702125 to your computer and use it in GitHub Desktop.
Save cbmeeks/7702125 to your computer and use it in GitHub Desktop.
Screen.asm
.importonce
/*
Character memory
$D018 = %xxxx000x -> charmem is at $0000
$D018 = %xxxx001x -> charmem is at $0800
$D018 = %xxxx010x -> charmem is at $1000
$D018 = %xxxx011x -> charmem is at $1800
$D018 = %xxxx100x -> charmem is at $2000
$D018 = %xxxx101x -> charmem is at $2800
$D018 = %xxxx110x -> charmem is at $3000
$D018 = %xxxx111x -> charmem is at $3800
Screen memory
$D018 = %0000xxxx -> screenmem is at $0000
$D018 = %0001xxxx -> screenmem is at $0400
$D018 = %0010xxxx -> screenmem is at $0800
$D018 = %0011xxxx -> screenmem is at $0c00
$D018 = %0100xxxx -> screenmem is at $1000
$D018 = %0101xxxx -> screenmem is at $1400
$D018 = %0110xxxx -> screenmem is at $1800
$D018 = %0111xxxx -> screenmem is at $1c00
$D018 = %1000xxxx -> screenmem is at $2000
$D018 = %1001xxxx -> screenmem is at $2400
$D018 = %1010xxxx -> screenmem is at $2800
$D018 = %1011xxxx -> screenmem is at $2c00
$D018 = %1100xxxx -> screenmem is at $3000
$D018 = %1101xxxx -> screenmem is at $3400
$D018 = %1110xxxx -> screenmem is at $3800
$D018 = %1111xxxx -> screenmem is at $3c00
*/
.macro SetScreenAndCharLocation(screen, charset) {
.print "Setting Screen Location to $" + toHexString(screen)
.print "Setting Char Location to $" + toHexString(charset)
lda #[[screen & $3FFF] / 64] | [[charset & $3FFF] / 1024]
sta $D018
}
// Set CUR_BUFFER to the selected buffer
// Bytes : Cycles (8 : 10)
.macro SetCurrentBuffer(buffer) {
lda #<buffer // (2 : 2)
sta CUR_BUFFER_PTR_LO // (2 : 3)
lda #>buffer // (2 : 2)
sta CUR_BUFFER_PTR_HI // (2 : 3)
}
.macro SetHiddenBuffer(buffer) {
lda #<buffer
sta DBL_BUFFER_PTR_LO
lda #>buffer
sta DBL_BUFFER_PTR_HI
}
.macro ToggleCURBUFFERFlag() {
lda CUR_BUFFER
eor #$01
sta CUR_BUFFER
}
.macro ClearScreen(screen, clearByte) {
lda #clearByte
ldx #0
!loop:
sta screen, x
sta screen + $100, x
sta screen + $200, x
sta screen + $300, x
inx
bne !loop-
}
.macro ClearColorRam(clearByte) {
lda #clearByte
ldx #0
!loop:
sta $D800, x
sta $D800 + $100, x
sta $D800 + $200, x
sta $D800 + $300, x
inx
bne !loop-
}
// $DD00 = %xxxxxx11 -> bank0: $0000-$3fff
// $DD00 = %xxxxxx10 -> bank1: $4000-$7fff
// $DD00 = %xxxxxx01 -> bank2: $8000-$bfff
// $DD00 = %xxxxxx00 -> bank3: $c000-$ffff
.macro SetVICBank0() {
lda $DD00
and #%11111100
ora #%00000011
sta $DD00
}
.macro SetVICBank1() {
lda $DD00
and #%11111100
ora #%00000010
sta $DD00
}
.macro SetVICBank2() {
lda $DD00
and #%11111100
ora #%00000001
sta $DD00
}
.macro SetVICBank3() {
lda $DD00
and #%11111100
ora #%00000000
sta $DD00
}
.macro SetBorderColor(color) {
lda #color
sta $d020
}
.macro SetBackgroundColor(color) {
lda #color
sta $d021
}
.macro SetMultiColor1(color) {
lda #color
sta $d022
}
.macro SetMultiColor2(color) {
lda #color
sta $d023
}
.macro SetMultiColorMode() {
lda $d016
ora #16
sta $d016
}
.macro SetScrollMode() {
lda $D016
eor #%00001000
sta $D016
}
//***************************************************************************
// Copying / Moving
//***************************************************************************
.pc = SCR_ROUTINES "Screen Routines"
copy_screen_left:
:BeginIRQ()
inc DELAY
lda DELAY
cmp #20
beq !continue+
jmp !exit+
!continue:
lda #0
sta DELAY
ldx #0
ldy #0
!continue:
lda SCR_X_POS
beq !loop0+
cmp #1
beq !loop1+
cmp #2
beq !loop2+
cmp #3
beq !loop3+
jmp !exit+
!loop0:
lda SCR_BUFFER + 1, x // $C801 => 01C8 => BD 01 C8
sta DBL_BUFFER, x // $CC00 => 00CC => 9D 00 CC
inx
bne !loop0-
lda #1
sta SCR_X_POS
jmp !exit+
!loop1:
lda SCR_BUFFER + 256 + 1, x // $C901 => 01C9 => BD 01 C9
sta DBL_BUFFER + 256, x // $CD00 => 00CD => 9D 00 CD
inx
bne !loop1-
lda #2
sta SCR_X_POS
jmp !exit+
!loop2:
lda SCR_BUFFER + 512 + 1, x // $CA01 => 01CA => BD 01 CA
sta DBL_BUFFER + 512, x // $CE00 => 00CE => 9D 00 CE
inx
bne !loop2-
lda #3
sta SCR_X_POS
jmp !exit+
!loop3: // Only need 32 chars on this last row
lda SCR_BUFFER + 768 + 1, x // $CB01 => 01CB => BD 01 CB
sta DBL_BUFFER + 768, x // $CF00 => 00CF => 9D 00 CF
inx
cpx #31
bne !loop3-
lda #0
sta SCR_X_POS
lda CUR_BUFFER
beq !flip+
:ToggleCURBUFFERFlag()
lda #$C8
sta !loop0- + 2
lda #$C9
sta !loop1- + 2
lda #$CA
sta !loop2- + 2
lda #$CB
sta !loop3- + 2
lda #$CC
sta !loop0- + 5
lda #$CD
sta !loop1- + 5
lda #$CE
sta !loop2- + 5
lda #$CF
sta !loop3- + 5
jmp !exit+
!flip:
:ToggleCURBUFFERFlag()
lda #$CC
sta !loop0- + 2
lda #$CD
sta !loop1- + 2
lda #$CE
sta !loop2- + 2
lda #$CF
sta !loop3- + 2
lda #$C8
sta !loop0- + 5
lda #$C9
sta !loop1- + 5
lda #$CA
sta !loop2- + 5
lda #$CB
sta !loop3- + 5
!exit:
lda #BLACK
sta $D020
:MoveIRQ(100, copy_screen_left)
:ReturnFromIRQ()
// lda SCR_BUFFER + 256 + 1, x
// sta SCR_BUFFER + 256, x
// ABCD
// ABCD
// ABCD
// BCDA
// BCDA
// BCD*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment