1
0
mirror of https://github.com/stid/woz64.git synced 2024-05-28 22:41:29 +00:00
woz64/libs/screen.asm

304 lines
9.2 KiB
NASM
Raw Normal View History

2019-11-06 04:31:17 +00:00
#importonce
2020-01-12 08:10:01 +00:00
#import "../libs/math.asm"
#import "../libs/memory.asm"
2020-01-19 06:48:59 +00:00
#import "../core/module.asm"
2020-01-13 07:33:13 +00:00
#import "../core/pseudo.asm"
2019-11-06 04:31:17 +00:00
2020-01-13 00:52:10 +00:00
// ========================================================
// ////// MACROS //////////////////////////////////////////
// ========================================================
2019-12-28 01:00:13 +00:00
2020-01-19 06:48:59 +00:00
* = * "Screen Lib"
2019-12-28 01:00:13 +00:00
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// ScreenClearChunks -
// Fast clear screen mem chunks.
//
// Parameters:
// baseAddress = Pointer to screen orcolor map Address
// clearByte = Byte to use to clear screen
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
.macro ScreenClearChunks(baseAddress, clearByte) {
2019-12-28 01:00:13 +00:00
lda #clearByte
ldx #0
!loop:
sta baseAddress, x
sta baseAddress + $100, x
sta baseAddress + $200, x
sta baseAddress + $300, x
inx
bne.r !loop-
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// ScreenClear -
// Fast clear screen characters mem.
//
// Parameters:
// clearByte = Byte to use to clear screen
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
.macro ScreenClear(clearByte) {
ScreenClearChunks(Screen.VIDEO_ADDR, clearByte)
2019-11-06 04:31:17 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// ScreenClear -
// Fast clear screen Color Ram.
//
// Parameters:
// clearByte = Byte to use to clear screen
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
.macro ScreenClearColorRam(clearByte) {
ScreenClearChunks(Screen.COLOR_ADDR, clearByte)
2019-11-06 04:31:17 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// ScreenSetBorderColor -
// Set Screen border color.
//
// Parameters:
// color = https://www.c64-wiki.com/wiki/Color
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
.macro ScreenSetBorderColor(color) {
2019-12-28 01:00:13 +00:00
lda #color
sta $d020
2019-11-06 04:31:17 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// ScreenSetBackgroundColor -
// Set Screen Backfground color.
//
// Parameters:
// color = https://www.c64-wiki.com/wiki/Color
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
.macro ScreenSetBackgroundColor(color) {
2019-12-28 01:00:13 +00:00
lda #color
sta $d021
2019-11-06 04:31:17 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// ScreenSetMultiColor1 -
// Set Screen Muticolor 1.
//
// Parameters:
// color = https://www.c64-wiki.com/wiki/Color
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
.macro ScreenSetMultiColor1(color) {
2019-12-28 01:00:13 +00:00
lda #color
sta $d022
2019-11-06 04:31:17 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// ScreenSetMultiColor2 -
// Set Screen Muticolor 2.
//
// Parameters:
// color = https://www.c64-wiki.com/wiki/Color
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
.macro ScreenSetMultiColor2(color) {
2019-12-28 01:00:13 +00:00
lda #color
sta $d023
2019-11-06 04:31:17 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// ScreenSetMultiColorMode -
// Set Screen Muticolor 2.
//
// Parameters:
// color = https://www.c64-wiki.com/wiki/Multicolor_Bitmap_Mode
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
.macro ScreenSetMultiColorMode() {
2019-12-28 01:00:13 +00:00
lda $d016
ora #16
sta $d016
2019-11-06 04:31:17 +00:00
}
.filenamespace Screen
2020-01-13 00:52:10 +00:00
// ========================================================
// ////// CONSTANTS ///////////////////////////////////////
// ========================================================
2019-11-06 04:31:17 +00:00
2019-12-28 01:00:13 +00:00
.label VIDEO_ADDR = $0400
.label COLOR_ADDR = $D800
.label COLUMN_NUM = 40
.label ROWS_NUM = 25
.label CR = $8e
.label BS = $95
2019-11-21 06:18:23 +00:00
2019-11-06 04:31:17 +00:00
2020-01-13 00:52:10 +00:00
// ========================================================
// ////// METHODS /////////////////////////////////////////
// ========================================================
2019-11-06 04:31:17 +00:00
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// init -
// Module Init.
// --------------------------------------------------------
2019-11-06 04:31:17 +00:00
init: {
2019-11-23 02:50:25 +00:00
lda #$00
sta MemMap.SCREEN.CursorCol
sta MemMap.SCREEN.CursorRow
rts
2019-11-18 03:28:54 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// toDebug -
// Print debug info.
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
toDebug: {
2020-01-13 00:52:10 +00:00
ModuleToDebug(module_type, module_name, version)
2020-01-12 08:10:01 +00:00
rts
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// scrollUp -
// Scroll the entire screen UP - 1 line
// --------------------------------------------------------
2019-11-18 03:28:54 +00:00
scrollUp: {
2019-11-23 02:50:25 +00:00
pha
2020-01-12 08:10:01 +00:00
MemoryClone(VIDEO_ADDR+40, VIDEO_ADDR+(COLUMN_NUM*(ROWS_NUM)), VIDEO_ADDR)
2019-11-23 02:50:25 +00:00
// clear last line
2019-12-28 01:00:13 +00:00
lda #32
ldx #40
2019-11-23 02:50:25 +00:00
!:
sta VIDEO_ADDR+(COLUMN_NUM*(ROWS_NUM-1)), x
dex
2019-12-28 01:00:13 +00:00
bpl !- // x == -1
2019-11-23 02:50:25 +00:00
dec MemMap.SCREEN.CursorRow
pla
rts
2019-11-18 03:28:54 +00:00
}
2019-11-06 04:31:17 +00:00
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// sendChar -
// Send a single char to the screen. Auto handle line feed,
// end of screen scrolling and Backspace.
//
// Parameters:
// A = Character to Print SCREEN ASCII
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
sendChar: {
2019-12-28 01:00:13 +00:00
sei
2020-01-13 07:33:13 +00:00
phx
2019-11-21 06:18:23 +00:00
cmp #CR
2019-11-18 03:28:54 +00:00
bne.r !+
jsr screenNewLine
2019-11-06 04:31:17 +00:00
iny
2019-11-21 06:18:23 +00:00
jmp exit
2019-11-23 02:50:25 +00:00
!:
2019-11-21 06:18:23 +00:00
cmp #BS
bne.r !+
ldx MemMap.SCREEN.CursorCol
cmp #0
beq exit
dec MemMap.SCREEN.CursorCol
2019-11-23 02:50:25 +00:00
!:
2019-11-06 04:31:17 +00:00
// Store Base Video Address 16 bit
2019-11-18 03:28:54 +00:00
ldx #<VIDEO_ADDR // Low byte
stx MemMap.SCREEN.TempVideoPointer
ldx #>VIDEO_ADDR // High byte
stx MemMap.SCREEN.TempVideoPointer+1
2019-11-06 04:31:17 +00:00
// Temp Save Y
2020-01-13 07:33:13 +00:00
phy
2019-11-06 04:31:17 +00:00
// CursorRow * 40
2019-11-18 03:28:54 +00:00
ldy MemMap.SCREEN.CursorRow
sty MemMap.MATH.factor1
ldy #COLUMN_NUM
sty MemMap.MATH.factor2
jsr Math.multiply
2019-11-06 04:31:17 +00:00
// Add mul result to TempVideoPointer
clc
pha
2019-11-18 03:28:54 +00:00
lda MemMap.MATH.result
adc MemMap.SCREEN.TempVideoPointer+1
sta MemMap.SCREEN.TempVideoPointer+1
lda MemMap.MATH.result+1
adc MemMap.SCREEN.TempVideoPointer
sta MemMap.SCREEN.TempVideoPointer
ldy MemMap.SCREEN.CursorCol
cpy #COLUMN_NUM // Is this > col num?
bcc.r noEndOfLine
jsr screenNewLine // Yes? Add new list first
ldy #1
cpy MemMap.SCREEN.ScrollUpTriggered
bne noScrollTriggered
2019-11-21 06:18:23 +00:00
// Compensate Scroll
2019-11-18 03:28:54 +00:00
sec
lda MemMap.SCREEN.TempVideoPointer
sbc #1
sta MemMap.SCREEN.TempVideoPointer
bcs !+
dec MemMap.SCREEN.TempVideoPointer+1
2019-11-23 02:50:25 +00:00
!:
2019-11-18 03:28:54 +00:00
2020-01-12 08:10:01 +00:00
noScrollTriggered:
noEndOfLine:
2019-11-06 04:31:17 +00:00
pla
2019-11-21 06:18:23 +00:00
// This is a backspace
2019-12-28 01:00:13 +00:00
cmp #BS
2020-01-12 08:10:01 +00:00
bne !+
2019-12-28 01:00:13 +00:00
lda #' '
2019-11-21 06:18:23 +00:00
sta (MemMap.SCREEN.TempVideoPointer), y
2020-01-19 07:11:56 +00:00
ply
2019-12-28 01:00:13 +00:00
jmp exit
2019-11-21 06:18:23 +00:00
2019-11-23 02:50:25 +00:00
!:
2019-11-18 03:28:54 +00:00
// insert into screen
sta (MemMap.SCREEN.TempVideoPointer), y
2020-01-13 07:33:13 +00:00
ply
2019-11-06 04:31:17 +00:00
iny
2019-11-18 03:28:54 +00:00
inc MemMap.SCREEN.CursorCol
2019-11-06 04:31:17 +00:00
2019-11-23 02:50:25 +00:00
exit:
2020-01-13 07:33:13 +00:00
plx
2019-12-28 01:00:13 +00:00
cli
2019-11-06 04:31:17 +00:00
rts
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// screenNewLine -
// Insert a New Line to screen - auto handle screen bottom
// linit scroll.
// --------------------------------------------------------
2019-11-06 04:31:17 +00:00
screenNewLine: {
2019-11-23 02:50:25 +00:00
pha
lda #0
sta MemMap.SCREEN.CursorCol
lda #ROWS_NUM-1
cmp MemMap.SCREEN.CursorRow // Are we at the screen bottom?
bne noScrollUp
jsr Screen.scrollUp
lda #1 // Yes - Scroll up
sta MemMap.SCREEN.ScrollUpTriggered
jmp done
noScrollUp:
lda #0
sta MemMap.SCREEN.ScrollUpTriggered
done:
inc MemMap.SCREEN.CursorRow
pla
rts
2019-11-06 04:31:17 +00:00
}
2020-01-19 06:48:59 +00:00
* = * "Screen Lib Data"
module_type: .byte Module.TYPES.LIB
2020-01-19 07:14:02 +00:00
version: .byte 1, 0, 1
2020-01-12 08:10:01 +00:00
module_name:
2020-01-13 00:52:10 +00:00
.text "screen"
2020-01-12 08:10:01 +00:00
.byte 0
2019-11-23 02:50:25 +00:00
2020-01-12 08:10:01 +00:00
#import "../core/mem_map.asm"