Skip to content

Commit

Permalink
Use new Shell API
Browse files Browse the repository at this point in the history
  • Loading branch information
adiee5 committed Jan 14, 2024
1 parent aae095c commit 1a4823b
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 86 deletions.
154 changes: 68 additions & 86 deletions neofetch.p8
Original file line number Diff line number Diff line change
@@ -1,162 +1,144 @@
%launcher none
%option no_sysinit
%zeropage basicsafe
%import shellroutines
%encoding iso
%address $4000

shell {
romsub $06e0 = print(str string @AY) clobbers(A,Y)
romsub $06e3 = print_uw(uword value @AY) clobbers(A,Y)
romsub $06e6 = print_uwhex(uword value @ AY, bool prefix @ Pc) clobbers(A,Y)
romsub $06e9 = print_uwbin(uword value @ AY, bool prefix @ Pc) clobbers(A,Y)
romsub $06ec = input_chars(uword buffer @ AY) clobbers(A) -> ubyte @Y
romsub $06ef = err_set(str message @AY) clobbers(Y) -> bool @A

; input registers set by shell upon calling your command:
; cx16.r0 = command address
; cx16.r1 = length of command (byte)
; cx16.r2 = arguments address
; cx16.r3 = length of arguments (byte)

; command should return error status in A. You can use err_set() to set a specific error message for the shell.
; command CAN use the FREE zero page locations.
; command CANNOT use memory below $4000 (the shell sits there)
; command CAN use Ram $0400-$06df.
}

main $4000 {
%option force_output

sub start(){

const ubyte COLOR_NORMAL = 1
const ubyte COLOR_HIGHLIGHT = 14 ; sadly it doesn't seem like those numbers can be fetched directly from shell.prg
&ubyte[] shellcolors=get_text_colors()

color(4)
shell.print(iso:"\r o o ")
shell.print("\r o o ")

color(COLOR_HIGHLIGHT)
shell.print(iso:"OS")
color(COLOR_NORMAL)
shell.print(iso:": Commander X16 KERNAL ROM ")
color(shellcolors[2])
shell.print("OS")
color(shellcolors[0])
shell.print(": Commander X16 KERNAL ROM ")
cx16.rombank(0)
byte ver = @($ff80) as byte
if ver == -1
shell.print(iso:"unstable")
shell.print("unstable")
else{
shell.print(iso:"R")
shell.chrout("R")
if ver < 0 ver *= -1
shell.print_uw(ver as uword)
shell.print_ub(ver)
}

color(4)
shell.print(iso:"\r M@\\ /@M ")
shell.print("\r M@\\ /@M ")

color(COLOR_HIGHLIGHT)
shell.print(iso:"Host")
color(COLOR_NORMAL)
shell.print(iso:": Commander X16 ")
color(shellcolors[2])
shell.print("Host")
color(shellcolors[0])
shell.print(": Commander X16 ")
if (@($9FBE)==$31) and (@($9FBF) == $36)
shell.print(iso:"Official Emulator")
else shell.print(iso:"gen1 board")
shell.print("Official Emulator")
else shell.print("gen1 board")
; TODO add functionality to distinguish gen2 and gen3 if it's going to be possible.
; Additionally add support for distinguishing Box16

color(14)
shell.print(iso:"\r M@@@\\ /@@@M ")
shell.print("\r M@@@\\ /@@@M ")

color(COLOR_HIGHLIGHT)
shell.print(iso:"Shell")
color(COLOR_NORMAL)
shell.print(iso:": SHELL.PRG") ;are version numbers even a thing there?
color(shellcolors[2])
shell.print("Shell")
color(shellcolors[0])
shell.print(": SHELL.PRG ") ;are version numbers even a thing there?
shell.print(shell.version()) ;yes, there are now!

color(14)
shell.print(iso:"\r :@@@@@\\ /@@@@@: ")
shell.print("\r :@@@@@\\ /@@@@@: ")

color(COLOR_HIGHLIGHT)
shell.print(iso:"Resolution")
color(COLOR_NORMAL)
color(shellcolors[2])
shell.print("Resolution")
color(shellcolors[0])
ubyte resx=0
ubyte resy=0
%asm {{
jsr cx16.get_screen_mode
stx p8v_resx
sty p8v_resy
}}
shell.print(iso:": ")
shell.print(": ")
shell.print_uw((resx as uword)*8)
shell.print(iso:"x")
shell.chrout("x")
shell.print_uw((resy as uword)*8)

color(3)
shell.print(iso:"\r \\@@@@@@\\ /@@@@@@/ ")
shell.print("\r \\@@@@@@\\ /@@@@@@/ ")

color(COLOR_HIGHLIGHT)
shell.print(iso:"CPU")
color(COLOR_NORMAL)
shell.print(iso:": WDC ")
color(shellcolors[2])
shell.print("CPU")
color(shellcolors[0])
shell.print(": WDC ")
if cputype()
shell.print(iso:"65c816")
else shell.print(iso:"65c02")
shell.print(iso:" (1) @ 8MHz")
shell.print("65c816")
else shell.print("65c02")
shell.print(" (1) @ 8MHz")

color(5)
shell.print(iso:"\r \'\'\"\"**N N**\"\"\'\' ")
shell.print("\r \'\'\"\"**N N**\"\"\'\' ")

color(COLOR_HIGHLIGHT)
shell.print(iso:"GPU")
color(COLOR_NORMAL)
shell.print(iso:": VERA module ")
color(shellcolors[2])
shell.print("GPU")
color(shellcolors[0])
shell.print(": VERA module ")
ubyte tmp_ctrl = cx16.VERA_CTRL
cx16.VERA_CTRL = $7e
if cx16.VERA_DC_VER0 == $56 {
shell.print(iso:"v")
shell.print_uw(cx16.VERA_DC_VER1 as uword)
shell.print(iso:".")
shell.print_uw(cx16.VERA_DC_VER2 as uword)
shell.print(iso:".")
shell.print_uw(cx16.VERA_DC_VER3 as uword)
shell.chrout("v")
shell.print_ub(cx16.VERA_DC_VER1)
shell.chrout(".")
shell.print_ub(cx16.VERA_DC_VER2)
shell.chrout(".")
shell.print_ub(cx16.VERA_DC_VER3)
}
cx16.VERA_CTRL = tmp_ctrl

color(7)
shell.print(iso:"\r N N ")
shell.print("\r N N ")

color(COLOR_HIGHLIGHT)
shell.print(iso:"Memory")
color(COLOR_NORMAL)
shell.print(iso:": ")
color(shellcolors[2])
shell.print("Memory")
color(shellcolors[0])
shell.print(": ")
shell.print_uw((sys.progend()-737) / 1024) ; 735 bytes of free golden ram + 2 bank registers = 737
shell.print(iso:"KiB / ")
shell.print("KiB / ")
shell.print_uw((cbm.MEMTOP(0, true)-2) / 1024)
shell.print(iso:"KiB")
shell.print("KiB")

color(7)
shell.print(iso:"\r ..-*N N*-.. ")
shell.print("\r ..-*N N*-.. ")

color(COLOR_HIGHLIGHT)
shell.print(iso:"Hi-Memory")
color(COLOR_NORMAL)
shell.print(iso:": ")
color(shellcolors[2])
shell.print("Hi-Memory")
color(shellcolors[0])
shell.print(": ")
shell.print_uw(cx16.numbanks() * $0008)
shell.print(iso:"KiB (")
shell.print("KiB (")
shell.print_uw(cx16.numbanks())
shell.print(iso:" banks)")
shell.print(" banks)")

color(8)
shell.print(iso:"\r :@@@@@/ \\@@@@@: ")
shell.print("\r :@@@@@/ \\@@@@@: ")
color(2)
shell.print(iso:"\r M@@@/ \\@@@M ")
shell.print("\r M@@@/ \\@@@M ")

ubyte j
for j in 0 to 15{
color(j)
shell.print(iso:"\xad#")
shell.print("\xad#")
}

color(2)
shell.print(iso:"\r M@/ \\@M ")
shell.print("\r M@/ \\@M ")

shell.print(iso:"\r")
shell.chrout("\r")
sys.exit(0)
}

Expand Down
28 changes: 28 additions & 0 deletions shellroutines.p8
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

; definitions for the callback routines the Shell provides for external commands.

shell {
romsub $07dc = version() -> uword @AY ; returns pointer to string with shell's version
romsub $07df = get_text_colors() -> uword @AY ; returns address of array of 5 text color bytes (text, background, highlight, prompt, error)
romsub $07e2 = chrout(ubyte character @A)
romsub $07e5 = print(str string @AY) clobbers(A,Y)
romsub $07e8 = print_ub(ubyte value @ A) clobbers(A,X,Y)
romsub $07eb = print_ubhex(ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y)
romsub $07ee = print_ubbin(ubyte value @ A, bool prefix @ Pc) clobbers(A,X,Y)
romsub $07f1 = print_uw(uword value @AY) clobbers(A,Y)
romsub $07f4 = print_uwhex(uword value @ AY, bool prefix @ Pc) clobbers(A,Y)
romsub $07f7 = print_uwbin(uword value @ AY, bool prefix @ Pc) clobbers(A,Y)
romsub $07fa = input_chars(uword buffer @ AY) clobbers(A) -> ubyte @Y
romsub $07fd = err_set(str message @AY) clobbers(Y) -> bool @A

; input registers set by shell upon calling your command:
; cx16.r0 = command address
; cx16.r1 = length of command (byte)
; cx16.r2 = arguments address
; cx16.r3 = length of arguments (byte)

; command should return error status in A. You can use err_set() to set a specific error message for the shell.
; command CAN use the FREE zero page locations.
; command CANNOT use memory below $4000 (the shell sits there)
; command CAN use Ram $0400-up to the jump table start.
}

0 comments on commit 1a4823b

Please sign in to comment.