This commit is contained in:
stid 2020-01-18 22:48:59 -08:00
parent 391ff1d7a3
commit 6af62c2859
12 changed files with 284 additions and 187 deletions

121
core/boot.asm Normal file
View File

@ -0,0 +1,121 @@
#importonce
#import "../core/pseudo.asm"
#import "../core/module.asm"
#import "../core/system.asm"
.filenamespace Boot
.const INIT_IRQ = $fda3
.const INIT_MEM = $fd50
.const INIT_IO = $fd15
.const INIT_VID = $ff5b
.const SCRN_CTRL = $d016
.const MAIN_COLOR = $03
.const BORDER_COLOR = $05
.const INTERRUPT_CTRL = $dc0d
.const NMSK_INTERRUPT_CTRL = $dd0d
.const TIMER_A_CTRL = $DC0E
* = * "Boot Core"
// ========================================================
// ////// METHODS /////////////////////////////////////////
// ========================================================
// --------------------------------------------------------
// coldstart -
// Power ON initialization
// --------------------------------------------------------
coldStart: {
ldx #$FF
sei
txs
cld
stx SCRN_CTRL // Set Screen Bits
jsr INIT_IRQ // Prepare IRQ
jsr INIT_MEM // Init memory. Rewrite this routine to speed up boot process.
jsr INIT_IO // Init I/O
jsr INIT_VID // Init video
cli
jmp warmStart
}
// --------------------------------------------------------
// warmStart -
// Restore pressed or program restart after first Power ON
// --------------------------------------------------------
warmStart: {
sei
lda #$7f
sta INTERRUPT_CTRL // disable timer interrupts which can be generated by the two CIA chips
sta NMSK_INTERRUPT_CTRL // the kernal uses such an interrupt to flash the cursor and scan the keyboard, so we better
// stop it.
lda INTERRUPT_CTRL // by reading this two registers we negate any pending CIA irqs.
lda NMSK_INTERRUPT_CTRL // if we don't do this, a pending CIA irq might occur after we finish setting up our irq.
// we don't want that to happen.
// Disable 0e TIMER
lda #254
and TIMER_A_CTRL
sta TIMER_A_CTRL
ScreenClearColorRam($00)
ScreenClear(' ')
ScreenSetBorderColor(BORDER_COLOR)
ScreenSetBackgroundColor(MAIN_COLOR)
cli
jsr Boot.init // Init Self as Module
jsr System.start // Start Core System
// If System Exit - reboot
// TODO: We can print a message here
// and delay a bit...
jmp warmStart
}
// --------------------------------------------------------
// init -
// Module Init.
// --------------------------------------------------------
init: {
// Sequence matter
jsr Module.init
jsr Pseudo.init
jsr System.init
rts
}
// --------------------------------------------------------
// toDebug -
// Print debug info.
// --------------------------------------------------------
toDebug: {
ModuleToDebug(module_type, module_name, version)
rts
}
// ========================================================
// ////// DATA ////////////////////////////////////////////
// ========================================================
* = * "Boot Core Data"
module_type: .byte Module.TYPES.CORE
version: .byte 1, 0, 0
.encoding "screencode_mixed"
module_name:
.text "boot"
.byte 0
#import "../core/mem_map.asm"

View File

@ -1,32 +1,37 @@
.filenamespace MemMap .filenamespace MemMap
#importonce #importonce
.const SHELL_BUGGER_ADDR = $3000 .const SHELL_BUFFER_ADDR = $1000 // 256 bytes (3000-30FF)
.const XSTACK_ADDRESS = $3100 .const XSTACK_ADDRESS = $1100 // 256 bytes (3100-31FF)
.const YSTACK_ADDRESS = $3200 .const YSTACK_ADDRESS = $1200 // 256 bytes (3200-32FF)
.const KEYB_RAM_CODE = $1300 // Safe to use > $1400
*=$2 "ZERO PAGE" virtual *=$2 "ZERO PAGE" virtual
.namespace CORE { .namespace CORE {
yStackOffset: .byte 0 // PHx/PLx pseudo commands
xStackOffset: .byte 0 yStackOffset: .byte 0 // Y Stack offset used by phy/ply
xStackOffset: .byte 0 // X Stack offset used by phx/plx
.label XStack = XSTACK_ADDRESS // 256 bytes phy/ply stack buffer pointer
.label YStack = YSTACK_ADDRESS // 256 bytes phx/plx stack buffer pointer
}
.label XStack = XSTACK_ADDRESS // 256 bytes .namespace PRINT {
.label YStack = YSTACK_ADDRESS // 256 bytes TempStringPointer: .word 0 // Pointer to string address as it get printend to screen
} }
.namespace SCREEN { .namespace SCREEN {
TempVideoPointer: .word 0 TempVideoPointer: .word 0 // Pointer to video mem used to target char pos
TempStringPointer: .word 0 CursorCol: .byte 0 // Actual cursor column position
CursorCol: .byte 0 CursorRow: .byte 0 // Actual cursor row position
CursorRow: .byte 0 ScrollUpTriggered: .byte 0 // Set to 1 if a scroll up was triggered
ScrollUpTriggered: .byte 0
} }
.namespace MATH { .namespace MATH {
factor1: .byte 0 factor1: .byte 0 // Factor 1 used in MUL ops
factor2: .byte 0 factor2: .byte 0 // Factor 2 used in MUL ops
result: .word 0
result: .word 0 // 16 Bit math operation result
} }
.namespace KEYBOARD { .namespace KEYBOARD {
@ -40,6 +45,8 @@
SYS_Delay: .byte 0 SYS_Delay: .byte 0
SYS_Kount: .byte 0 SYS_Kount: .byte 0
SYS_Lstshf: .byte 0 SYS_Lstshf: .byte 0
.label keybRamCode = KEYB_RAM_CODE
} }
.namespace MEMORY { .namespace MEMORY {
@ -63,7 +70,7 @@
XAML: .byte 0 XAML: .byte 0
XAMH: .byte 0 XAMH: .byte 0
.label buffer = SHELL_BUGGER_ADDR // 256 bytes .label buffer = SHELL_BUFFER_ADDR // 256 bytes
} }

View File

@ -1,5 +1,5 @@
#importonce #importonce
#import "print.asm" #import "../libs/print.asm"
// ======================================================== // ========================================================
// ////// MACROS ////////////////////////////////////////// // ////// MACROS //////////////////////////////////////////
@ -101,13 +101,13 @@ printVersion: {
sta MemMap.MODULE.versionPtr sta MemMap.MODULE.versionPtr
stx MemMap.MODULE.versionPtr+1 stx MemMap.MODULE.versionPtr+1
ldy #0 ldy #0
jsr printNext jsr printNext // Major
lda #'.' lda #'.'
PrintChar() PrintChar()
jsr printNext jsr printNext // Minor
lda #'.' lda #'.'
PrintChar() PrintChar()
jsr printNext jsr printNext // Revision
rts rts
printNext: printNext:
lda (MemMap.MODULE.versionPtr), y lda (MemMap.MODULE.versionPtr), y
@ -154,8 +154,8 @@ printType: {
// ======================================================== // ========================================================
* = * "Module Lib Data" * = * "Module Lib Data"
module_type: .byte Module.TYPES.LIB module_type: .byte Module.TYPES.CORE
version: .byte 1, 1, 0 version: .byte 1, 2, 0
.encoding "screencode_mixed" .encoding "screencode_mixed"
module_name: module_name:

View File

@ -1,6 +1,6 @@
#importonce #importonce
#import "../core/mem_map.asm" #import "../core/mem_map.asm"
#import "../libs/module.asm" #import "../core/module.asm"
// ======================================================== // ========================================================

View File

@ -1,54 +1,79 @@
#importonce #importonce
#import "../core/pseudo.asm"
#import "../core/module.asm"
#import "../core/boot.asm"
#import "../libs/memory.asm" #import "../libs/memory.asm"
#import "../libs/math.asm" #import "../libs/math.asm"
#import "../libs/print.asm" #import "../libs/print.asm"
#import "../core/keyboard.asm" #import "../libs/keyboard.asm"
#import "../core/screen.asm" #import "../libs/screen.asm"
#import "../core/pseudo.asm"
#import "../libs/module.asm"
#import "../progs/woz_shell.asm" #import "../progs/woz_shell.asm"
.filenamespace Init .filenamespace System
* = * "Init Core" * = * "System Core"
// ======================================================== // ========================================================
// ////// METHODS ///////////////////////////////////////// // ////// METHODS /////////////////////////////////////////
// ======================================================== // ========================================================
// --------------------------------------------------------
// start -
// System Start
// --------------------------------------------------------
start: {
// Start Main Program
jsr WozShell.start
// TODO: Program exited here
// We can ask program to set a ram param and let us know
// if exit is due to a sort of error.
rts
// TODO: Can we use Timed Interrupt to execute small system recurring tasks?
}
// -------------------------------------------------------- // --------------------------------------------------------
// init - // init -
// Module Init. // Module Init.
// -------------------------------------------------------- // --------------------------------------------------------
init: { init: {
// Init All Modules // Init All Modules
jsr Pseudo.init // TODO: How we can make this dynamic?
jsr Module.init
jsr Memory.init jsr Memory.init
jsr Math.init
jsr Print.init
jsr Keyboard.init
jsr Screen.init jsr Screen.init
jsr Print.init
jsr Math.init
jsr Keyboard.init
jsr WozShell.init jsr WozShell.init
rts rts
} }
// -------------------------------------------------------- // --------------------------------------------------------
// toDebug - // toDebug -
// Print debug info. // Print debug info.
// -------------------------------------------------------- // --------------------------------------------------------
toDebug: { toDebug: {
// Debug All Modules // Debug All Modules
jsr Boot.toDebug
ModuleToDebug(module_type, module_name, version) ModuleToDebug(module_type, module_name, version)
jsr Keyboard.toDebug
jsr Screen.toDebug
jsr Pseudo.toDebug jsr Pseudo.toDebug
jsr Module.toDebug jsr Module.toDebug
jsr Keyboard.toDebug
jsr Math.toDebug
jsr Memory.toDebug jsr Memory.toDebug
jsr Print.toDebug jsr Print.toDebug
jsr Math.toDebug jsr Screen.toDebug
jsr WozShell.toDebug jsr WozShell.toDebug
rts rts
} }
@ -58,13 +83,13 @@ toDebug: {
// ////// DATA //////////////////////////////////////////// // ////// DATA ////////////////////////////////////////////
// ======================================================== // ========================================================
* = * "Init Core Data" * = * "System Core Data"
module_type: .byte Module.TYPES.CORE module_type: .byte Module.TYPES.CORE
version: .byte 1, 1, 0 version: .byte 1, 0, 0
.encoding "screencode_mixed" .encoding "screencode_mixed"
module_name: module_name:
.text "init" .text "system"
.byte 0 .byte 0

View File

@ -1,7 +1,7 @@
#importonce #importonce
#import "../libs/module.asm" #import "../core/module.asm"
#import "../libs/memory.asm" #import "../libs/memory.asm"
#import "../libs/module.asm" #import "../core/module.asm"
.filenamespace Keyboard .filenamespace Keyboard
@ -18,7 +18,11 @@
.const cSYS_DelayValue = 32 .const cSYS_DelayValue = 32
.const cKeybW_Row1 = $FE .const cKeybW_Row1 = $FE
* = * "Keyboard Module" .const RASTER_LINE = $d012
* = * "Keyboard Lib"
// ======================================================== // ========================================================
// ////// METHODS ROM ///////////////////////////////////// // ////// METHODS ROM /////////////////////////////////////
@ -49,7 +53,26 @@ init: {
sta MemMap.KEYBOARD.SYS_Xmax sta MemMap.KEYBOARD.SYS_Xmax
// Clone self altering Methods to RAM // Clone self altering Methods to RAM
MemoryClone(cloneStart, cloneEnd, $1000) MemoryClone(cloneStart, cloneEnd, MemMap.KEYBOARD.keybRamCode)
rts
}
// --------------------------------------------------------
// waitForKey -
// Loop until a new key is available.
//
// Result:
// A = Pressed key code
// --------------------------------------------------------
waitForKey: {
loop:
lda #$FF
raster:
cmp RASTER_LINE // Raster done?
bne raster
jsr Keyboard.ReadKeyb
jsr Keyboard.GetKey
bcs loop
rts rts
} }
@ -63,7 +86,7 @@ toDebug: {
} }
// ======================================================== // ========================================================
// ////// KEYMAPPING RON ////////////////////////////////// // ////// KEYMAPPING ROM //////////////////////////////////
// ======================================================== // ========================================================
KeyMapVec: KeyMapVec:
@ -144,7 +167,7 @@ cloneStart:
// bcs loop // bcs loop
// // Key here is in A // // Key here is in A
// -------------------------------------------------------- // --------------------------------------------------------
.pseudopc $1000 { .pseudopc MemMap.KEYBOARD.keybRamCode {
ReadKeyb: { ReadKeyb: {
lda #<KeyMap1 lda #<KeyMap1
sta @SMC_Vec sta @SMC_Vec
@ -333,8 +356,8 @@ cloneEnd:
// ////// DATA //////////////////////////////////////////// // ////// DATA ////////////////////////////////////////////
// ======================================================== // ========================================================
* = * "Keyboard Module Data" * = * "Keyboard Lib Data"
module_type: .byte Module.TYPES.CORE module_type: .byte Module.TYPES.LIB
version: .byte 1, 1, 0 version: .byte 1, 1, 0
.encoding "screencode_mixed" .encoding "screencode_mixed"

View File

@ -1,12 +1,12 @@
#importonce #importonce
#import "../libs/module.asm" #import "../core/module.asm"
#import "../libs/module.asm" #import "../core/module.asm"
.filenamespace Math .filenamespace Math
* = * "Math Lin" * = * "Math Lib"
// ======================================================== // ========================================================
// ////// METHODS ///////////////////////////////////////// // ////// METHODS /////////////////////////////////////////

View File

@ -1,7 +1,7 @@
#importonce #importonce
#import "../libs/module.asm" #import "../core/module.asm"
#import "../libs/module.asm" #import "../core/module.asm"
#import "../core/pseudo.asm" #import "../core/pseudo.asm"
@ -223,5 +223,5 @@ module_name:
#import "../core/mem_map.asm" #import "../core/mem_map.asm"
#import "../core/screen.asm" #import "../libs/screen.asm"

View File

@ -1,8 +1,8 @@
#importonce #importonce
#import "math.asm" #import "math.asm"
#import "../core/screen.asm" #import "../libs/screen.asm"
#import "../libs/module.asm" #import "../core/module.asm"
// ======================================================== // ========================================================
@ -75,10 +75,10 @@ printPetChar: {
// -------------------------------------------------------- // --------------------------------------------------------
printLine: { printLine: {
ldy #$00 ldy #$00
sta MemMap.SCREEN.TempStringPointer sta MemMap.PRINT.TempStringPointer
stx MemMap.SCREEN.TempStringPointer+1 stx MemMap.PRINT.TempStringPointer+1
printLoop: printLoop:
lda (MemMap.SCREEN.TempStringPointer), y lda (MemMap.PRINT.TempStringPointer), y
cmp #0 cmp #0
beq exit beq exit
jsr Screen.sendChar jsr Screen.sendChar

View File

@ -1,7 +1,7 @@
#importonce #importonce
#import "../libs/math.asm" #import "../libs/math.asm"
#import "../libs/memory.asm" #import "../libs/memory.asm"
#import "../libs/module.asm" #import "../core/module.asm"
#import "../core/pseudo.asm" #import "../core/pseudo.asm"
@ -10,7 +10,7 @@
// ======================================================== // ========================================================
* = * "Screen Module" * = * "Screen Lib"
// -------------------------------------------------------- // --------------------------------------------------------
// ScreenClearChunks - // ScreenClearChunks -
@ -292,8 +292,8 @@ screenNewLine: {
rts rts
} }
* = * "Screen Module Data" * = * "Screen Lib Data"
module_type: .byte Module.TYPES.CORE module_type: .byte Module.TYPES.LIB
version: .byte 1, 0, 0 version: .byte 1, 0, 0
module_name: module_name:
.text "screen" .text "screen"

117
main.asm
View File

@ -1,124 +1,17 @@
.cpu _6502 .cpu _6502
//BasicUpstart2(start) //BasicUpstart2(Boot.warmStart)
#import "./core/mem_map.asm" #import "./core/mem_map.asm"
* = $8000 "Main" * = $8000 "Main"
//------------------------------------------------------------------------------------ .word Boot.coldStart // coldstart vector
.const MAIN_COLOR = $03 .word Boot.warmStart // start vector
.const BORDER_COLOR = $05 .byte $C3,$C2,$CD,'8','0' //..CBM80..
.const CR = $0d
.const BS = $14
.const ADV_CHAR = '@'
.const INIT_IRQ = $fda3
.const INIT_MEM = $fd50
.const INIT_IO = $fd15
.const INIT_VID = $ff5b
.const SCRN_CTRL = $d016
.const RASTER_LINE = $d012
.const INTERRUPT_CTRL = $dc0d
.const NMSK_INTERRUPT_CTRL = $dd0d
.const TIMER_A_CTRL = $DC0E
//------------------------------------------------------------------------------------ #import "./core/boot.asm"
.word coldstart // coldstart vector
.word start // start vector
.byte $C3,$C2,$CD,'8','0' //..CBM80..
//------------------------------------------------------------------------------------
#import "./core/init.asm"
#import "./libs/print.asm"
#import "./core/screen.asm"
#import "./core/keyboard.asm"
#import "./progs/woz_shell.asm"
//------------------------------------------------------------------------------------
// Main Program
//------------------------------------------------------------------------------------
* = * "Kernel Start"
coldstart: {
ldx #$FF
sei
txs
cld
stx SCRN_CTRL // Set Screen Bits
jsr INIT_IRQ // Prepare IRQ
jsr INIT_MEM // Init memory. Rewrite this routine to speed up boot process.
jsr INIT_IO // Init I/O
jsr INIT_VID // Init video
cli
}
* = * "App Start"
//------------------------------------------------------------------------------------
start: {
jsr initApp;
jsr WozShell.start
loop:
lda #$FF
Raster:
cmp RASTER_LINE // Raster done?
bne Raster
jsr Keyboard.ReadKeyb
jsr Keyboard.GetKey
bcs loop
cmp #CR
beq execute
cmp #BS
beq backspace
inputChar:
jsr WozShell.push // Char in Buffer
PrintChar()
jmp loop
backspace:
jsr WozShell.backspace
PrintChar()
jmp loop
execute:
jsr WozShell.push // CR in Buffer
jsr Screen.screenNewLine
jsr WozShell.exec
jsr Screen.screenNewLine
jsr WozShell.clear
jmp loop
}
//------------------------------------------------------------------------------------
initApp: {
sei
lda #$7f
sta INTERRUPT_CTRL // disable timer interrupts which can be generated by the two CIA chips
sta NMSK_INTERRUPT_CTRL // the kernal uses such an interrupt to flash the cursor and scan the keyboard, so we better
// stop it.
lda INTERRUPT_CTRL // by reading this two registers we negate any pending CIA irqs.
lda NMSK_INTERRUPT_CTRL // if we don't do this, a pending CIA irq might occur after we finish setting up our irq.
// we don't want that to happen.
// Disable 0e TIMER
lda #254
and TIMER_A_CTRL
sta TIMER_A_CTRL
ScreenClearColorRam($00)
ScreenClear(' ')
ScreenSetBorderColor(BORDER_COLOR)
ScreenSetBackgroundColor(MAIN_COLOR)
jsr Init.init
cli
rts
}
//------------------------------------------------------------------------------------
* = * "Kernel Data" * = * "Kernel Data"
* = $9FFF "EpromFiller" * = $9FFF "EpromFiller"
.byte 0 .byte 0

View File

@ -1,8 +1,9 @@
#importonce #importonce
#import "../libs/print.asm"
#import "../libs/module.asm"
#import "../core/init.asm"
#import "../core/pseudo.asm" #import "../core/pseudo.asm"
#import "../core/system.asm"
#import "../libs/print.asm"
#import "../core/module.asm"
#import "../libs/keyboard.asm"
.filenamespace WozShell .filenamespace WozShell
@ -12,9 +13,9 @@
// ////// CONSTANTS /////////////////////////////////////// // ////// CONSTANTS ///////////////////////////////////////
// ======================================================== // ========================================================
.const CR = $0d .const R = $52
.const R = $52 .const CR = $0d
.const BS = $14
// ======================================================== // ========================================================
// ////// METHODS ///////////////////////////////////////// // ////// METHODS /////////////////////////////////////////
@ -32,7 +33,34 @@ start: {
PrintLine(lineString) PrintLine(lineString)
PrintLine(aboutString) PrintLine(aboutString)
PrintLine(lineString) PrintLine(lineString)
rts jmp WozShell.loop
}
//------------------------------------------------------------------------------------
loop: {
jsr Keyboard.waitForKey
cmp #CR
beq execute
cmp #BS
beq backspace
inputChar:
jsr WozShell.push // Char in Buffer
PrintChar()
jmp loop
backspace:
jsr WozShell.backspace
PrintChar()
jmp loop
execute:
jsr WozShell.push // CR in Buffer
jsr Screen.screenNewLine
jsr WozShell.exec
jsr Screen.screenNewLine
jsr WozShell.clear
jmp loop
} }
toDebug: { toDebug: {
@ -81,7 +109,7 @@ stidExec: {
cmp #$52 // R cmp #$52 // R
beq cmdReset beq cmdReset
cmp #$56 // Z cmp #$56 // V
beq cmdZeroPageInfo beq cmdZeroPageInfo
done: done:
rts rts
@ -93,7 +121,7 @@ stidExec: {
jmp $fce2 // SYS 64738 jmp $fce2 // SYS 64738
cmdZeroPageInfo: cmdZeroPageInfo:
jsr Init.toDebug jsr System.toDebug
jmp done jmp done
} }
@ -237,13 +265,13 @@ wozExec: {
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
PRBYTE: PRBYTE:
pha // Save A for LSD pha // Save A for LSD
lsr lsr
lsr lsr
lsr // MSD to LSD position lsr // MSD to LSD position
lsr lsr
jsr PRHEX // Output hex digit jsr PRHEX // Output hex digit
pla // Restore A pla // Restore A
// Fall through to print hex routine // Fall through to print hex routine