woz64/progs/woz_shell.asm

422 lines
13 KiB
NASM
Raw Normal View History

2019-11-17 07:41:00 +00:00
#importonce
2020-01-13 07:33:13 +00:00
#import "../core/pseudo.asm"
2020-01-19 06:48:59 +00:00
#import "../core/system.asm"
#import "../libs/print.asm"
2020-03-09 05:57:30 +00:00
#import "../libs/timers.asm"
2020-01-19 06:48:59 +00:00
#import "../core/module.asm"
2020-01-21 02:09:18 +00:00
#import "../hardware/vic.asm"
2020-01-20 07:32:37 +00:00
#import "../devices/keyboard.asm"
2020-03-09 05:57:30 +00:00
#import "../devices/video.asm"
2020-01-21 02:09:18 +00:00
#import "../hardware/mem_map.asm"
2019-11-17 07:41:00 +00:00
2020-01-13 00:52:10 +00:00
.filenamespace WozShell
2020-03-09 05:57:30 +00:00
2020-01-12 08:10:01 +00:00
* = * "WozShell Routines"
2019-11-17 07:41:00 +00:00
2020-01-13 00:52:10 +00:00
// ========================================================
// ////// CONSTANTS ///////////////////////////////////////
// ========================================================
2020-01-19 06:48:59 +00:00
.const R = $52
.const CR = $0d
.const BS = $14
2019-11-23 02:50:25 +00:00
.const MAX_CMD_BUFFER = 40
2020-01-13 00:52:10 +00:00
// ========================================================
// ////// METHODS /////////////////////////////////////////
// ========================================================
2019-11-18 03:28:54 +00:00
clear:
2019-11-17 07:41:00 +00:00
init: {
2020-01-13 01:24:10 +00:00
lda #-1
sta MemMap.SHELL.pos
rts
2019-11-17 07:41:00 +00:00
}
2020-01-12 08:10:01 +00:00
start: {
2020-01-13 01:24:10 +00:00
PrintLine(lineString)
PrintLine(aboutString)
PrintLine(lineString)
2020-01-21 02:09:18 +00:00
//jsr WozShell.startCursor
2020-01-19 06:48:59 +00:00
jmp WozShell.loop
}
2020-01-21 02:09:18 +00:00
startCursor: {
sei
lda #$01
sta Vic.INTE
lda #<cursortInt
ldx #>cursortInt
sta $314 // store in $314/$315
stx $315
lda #$00
sta Vic.RCNT
lda $d011
and #$7f
sta $d011
cli
rts
cursortInt: {
dec $d019 // ACK INT
pla
tay
pla
tax
pla
rti
}
}
2020-01-19 06:48:59 +00:00
//------------------------------------------------------------------------------------
loop: {
jsr Keyboard.waitForKey
cmp #CR
beq execute
cmp #BS
beq backspace
inputChar:
jsr WozShell.push // Char in Buffer
cpy #MAX_CMD_BUFFER
beq loop
2020-01-19 06:48:59 +00:00
PrintChar()
jmp loop
backspace:
jsr WozShell.backspace
PrintChar()
jmp loop
execute:
jsr WozShell.push // CR in Buffer
2020-01-20 07:32:37 +00:00
jsr Video.screenNewLine
2020-01-19 06:48:59 +00:00
jsr WozShell.exec
2020-01-20 07:32:37 +00:00
jsr Video.screenNewLine
2020-01-19 06:48:59 +00:00
jsr WozShell.clear
jmp loop
2020-01-12 08:10:01 +00:00
}
toDebug: {
2020-01-13 01:24:10 +00:00
ModuleToDebug(module_type, module_name, version)
rts
2020-01-12 08:10:01 +00:00
}
2019-11-17 07:41:00 +00:00
push: {
2020-01-13 01:24:10 +00:00
ldy MemMap.SHELL.pos
iny
cpy #MAX_CMD_BUFFER
2020-01-20 07:32:37 +00:00
beq done
2020-01-13 01:24:10 +00:00
sty MemMap.SHELL.pos
sta MemMap.SHELL.buffer, y
done:
rts
2019-11-17 07:41:00 +00:00
}
2019-11-21 06:18:23 +00:00
backspace: {
2020-01-13 01:24:10 +00:00
ldy MemMap.SHELL.pos
cpy #-1
beq done
dey
sty MemMap.SHELL.pos
done:
rts
2019-11-21 06:18:23 +00:00
}
2019-12-28 01:00:13 +00:00
exec: {
2020-01-13 01:24:10 +00:00
lda MemMap.SHELL.buffer // Check first char
cmp #'!'
beq stidExec // if ! is stid mon command
jmp wozExec // Otherwise exec Woz
// Expect exec functions to RTS
2019-12-28 01:00:13 +00:00
}
stidExec: {
2020-01-13 01:24:10 +00:00
ldy #1
2019-12-28 01:00:13 +00:00
2020-01-13 01:24:10 +00:00
lda MemMap.SHELL.buffer, y
2019-12-28 01:00:13 +00:00
2020-01-13 01:24:10 +00:00
cmp #$48 // H
beq cmdHelp
2020-01-12 08:10:01 +00:00
2020-01-13 01:24:10 +00:00
cmp #$52 // R
beq cmdReset
2019-12-28 01:00:13 +00:00
2020-01-19 06:48:59 +00:00
cmp #$56 // V
2020-03-09 05:57:30 +00:00
beq cmdSysInfo
.break
cmp #$54 // T
beq cmdTest
2020-01-13 01:24:10 +00:00
done:
rts
// STID Commands
cmdHelp:
PrintLine(helpString)
jmp done
cmdReset:
jmp $fce2 // SYS 64738
2020-03-09 05:57:30 +00:00
cmdSysInfo:
2020-01-19 06:48:59 +00:00
jsr System.toDebug
2020-01-13 01:24:10 +00:00
jmp done
2020-03-09 05:57:30 +00:00
cmdTest: {
// TODO: Optizime for code size here
ldy #1
loop:
tya
jsr clearVideo
jsr clearColors
jsr Timers.delayOne
iny
bne loop
VideoClearColorRam($03)
jmp done
clearVideo: {
ldx #0
!loop:
sta $0400, x
sta $0400 + $100, x
sta $0400 + $200, x
sta $0400 + $300, x
inx
bne !loop-
rts
}
clearColors: {
ldx #0
!loop:
sta $d800, x
sta $d800 + $100, x
sta $d800 + $200, x
sta $d800 + $300, x
inx
bne !loop-
rts
}
}
2019-12-28 01:00:13 +00:00
}
2019-11-17 07:41:00 +00:00
// WOZ MONITOR FLOW - FROM APPLE1
wozExec: {
2020-01-13 01:24:10 +00:00
ldy #-1
lda #0
tax
SETSTOR:
asl
SETMODE:
cmp #0
2020-01-20 07:32:37 +00:00
beq !+
2020-01-13 01:24:10 +00:00
eor #%10000000
2019-11-17 08:52:55 +00:00
!:
2020-01-13 01:24:10 +00:00
sta MemMap.SHELL.MODE
BLSKIP: iny
NEXTITEM:
lda MemMap.SHELL.buffer,Y //Get character
cmp #CR
2020-01-20 07:32:37 +00:00
bne CONT // We're done if it's CR!
2020-01-13 01:24:10 +00:00
rts
CONT:
cmp #'.'
bcc BLSKIP // Ignore everything below "."!
beq SETMODE // Set BLOCK XAM mode ("." = $AE)
cmp #':'
beq SETSTOR // Set STOR mode! $BA will become $7B
cmp #R
beq RUN // Run the program! Forget the rest
stx MemMap.SHELL.L // Clear input value (X=0)
stx MemMap.SHELL.H
sty MemMap.SHELL.YSAV // Save Y for comparison
2019-11-17 07:41:00 +00:00
// Here we're trying to parse a new hex value
2020-01-13 01:24:10 +00:00
NEXTHEX:
lda MemMap.SHELL.buffer,y // Get character for hex test
eor #$30 // Map digits to 0-9
cmp #9+1 // Is it a decimal digit?
bcc DIG // Yes!
adc #$88 // Map letter "A"-"F" to $FA-FF
cmp #$FA // Hex letter?
bcc NOTHEX // No! Character not hex
DIG:
asl
asl // Hex digit to MSD of A
asl
asl
ldx #4 // Shift count
HEXSHIFT:
asl // Hex digit left, MSB to carry
rol MemMap.SHELL.L // Rotate into LSD
rol MemMap.SHELL.H // Rotate into MSD's
dex // Done 4 shifts?
bne HEXSHIFT // No, loop
iny // Advance text index
bne NEXTHEX // Always taken
NOTHEX: cpy MemMap.SHELL.YSAV //Was at least 1 hex digit given?
bne !+ // No! Ignore all, start from scratch
rts
!:
bit MemMap.SHELL.MODE //Test MODE byte
bvc NOTSTOR // B6=0 is STOR, 1 is XAM or BLOCK XAM
2019-11-17 07:41:00 +00:00
// STOR mode, save LSD of new hex byte
2020-01-13 01:24:10 +00:00
lda MemMap.SHELL.L // LSD's of hex data
sta (MemMap.SHELL.STL,X) //Store current 'store index'(X=0)
inc MemMap.SHELL.STL //Increment store index.
bne NEXTITEM // No carry!
inc MemMap.SHELL.STH // Add carry to 'store index' high
TONEXTITEM:
jmp NEXTITEM //Get next command item.
2019-11-17 07:41:00 +00:00
//-------------------------------------------------------------------------
// RUN user's program from last opened location
//-------------------------------------------------------------------------
2020-01-13 01:24:10 +00:00
RUN: jmp (MemMap.SHELL.XAML) // Run user's program
2019-11-17 07:41:00 +00:00
//-------------------------------------------------------------------------
// We're not in Store mode
//-------------------------------------------------------------------------
2020-01-13 01:24:10 +00:00
NOTSTOR:
bmi XAMNEXT // B7 = 0 for XAM, 1 for BLOCK XAM
2019-11-17 07:41:00 +00:00
// We're in XAM mode now
2020-01-13 01:24:10 +00:00
ldx #2 // Copy 2 bytes
2020-01-13 07:33:13 +00:00
SETADR:
lda MemMap.SHELL.L-1,X // Copy hex data to
2020-01-13 01:24:10 +00:00
sta MemMap.SHELL.STL-1,X // 'store index'
sta MemMap.SHELL.XAML-1,X // and to 'XAM index'
dex // Next of 2 bytes
bne SETADR // Loop unless X = 0
2019-11-17 07:41:00 +00:00
// Print address and data from this address, fall through next BNE.
2020-01-13 01:24:10 +00:00
NXTPRNT:
bne PRDATA // NE means no address to print
lda #CR // Print CR first
PrintChar()
lda MemMap.SHELL.XAMH // Output high-order byte of address
jsr PRBYTE
lda MemMap.SHELL.XAML // Output low-order byte of address
jsr PRBYTE
lda #':' // Print colon
PrintChar()
PRDATA: lda #' ' // Print space
PrintChar()
lda (MemMap.SHELL.XAML,X) // Get data from address (X=0)
jsr PRBYTE // Output it in hex format
XAMNEXT:
stx MemMap.SHELL.MODE // 0 -> MODE (XAM mode).
lda MemMap.SHELL.XAML // See if there's more to print
cmp MemMap.SHELL.L
lda MemMap.SHELL.XAMH
sbc MemMap.SHELL.H
bcs TONEXTITEM // Not less! No more data to output
inc MemMap.SHELL.XAML // Increment 'examine index'
bne MOD8CHK // No carry!
inc MemMap.SHELL.XAMH
MOD8CHK:
lda MemMap.SHELL.XAML // If address MOD 8 = 0 start new line
and #%00000111
bpl NXTPRNT // Always taken.
2019-11-17 07:41:00 +00:00
// -------------------------------------------------------------------------
// Subroutine to print a byte in A in hex form (destructive)
// -------------------------------------------------------------------------
2020-01-13 01:24:10 +00:00
PRBYTE:
2020-01-19 06:48:59 +00:00
pha // Save A for LSD
2020-01-13 01:24:10 +00:00
lsr
lsr
lsr // MSD to LSD position
lsr
2020-01-19 06:48:59 +00:00
jsr PRHEX // Output hex digit
pla // Restore A
2019-11-17 07:41:00 +00:00
// Fall through to print hex routine
// -------------------------------------------------------------------------
// Subroutine to print a hexadecimal digit
// -------------------------------------------------------------------------
2020-01-13 01:24:10 +00:00
PRHEX: and #%00001111 // Mask LSD for hex print
ora #'0' // Add "0"
cmp #'9'+1 // Is it a decimal digit?
bcc !+ // Yes! output it
adc #6 // Add offset for letter A-F
!:
PrintChar()
rts
2019-11-23 02:50:25 +00:00
}
2020-01-13 00:52:10 +00:00
// ========================================================
// ////// DATA ////////////////////////////////////////////
// ========================================================
2020-01-12 08:10:01 +00:00
* = * "WozShell Data"
2020-01-13 01:24:10 +00:00
module_type: .byte Module.TYPES.PROG
2020-01-21 02:09:18 +00:00
version: .byte 1, 5, 0
2019-12-28 01:00:13 +00:00
.encoding "screencode_mixed"
2020-01-12 08:10:01 +00:00
module_name:
2020-01-13 01:24:10 +00:00
.text "woz-shell"
.byte 0
2019-12-28 01:00:13 +00:00
helpString:
2020-01-13 01:24:10 +00:00
.text "----------------------"
.byte $8e
.text "h : this help"
.byte $8e
.text "r : hard reset"
.byte $8e
.text "v : modue versions"
.byte $8e
.text "----------------------"
.byte $8e, 0
2020-01-12 08:10:01 +00:00
aboutString:
2020-03-09 05:57:30 +00:00
.text "woz64 mon - v 1.6.0"
2020-01-13 01:24:10 +00:00
.byte $8e, 0
2020-01-12 08:10:01 +00:00
lineString:
2020-01-13 01:24:10 +00:00
.text "----------------------------------------"
.byte $8e, 0
2020-01-12 08:10:01 +00:00
2020-01-20 07:38:20 +00:00
#import "../hardware/mem_map.asm"