Skip to content

Commit

Permalink
various improvements:
Browse files Browse the repository at this point in the history
fix verafx.available().
added gfx_lores.plot().
faster gfx_lores.clear_screen().
added a new Sublime Text 4 syntax highlighting file.
  • Loading branch information
irmen committed Oct 1, 2024
1 parent ea3871d commit c13168b
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 51 deletions.
90 changes: 48 additions & 42 deletions compiler/res/prog8lib/cx16/gfx_lores.p8
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
; bitmap image needs to start at VRAM addres $00000.
; This is compatible with the CX16's screen mode 128. (void cx16.set_screen_mode(128))

%import verafx


gfx_lores {

Expand All @@ -19,15 +21,47 @@ gfx_lores {
}

sub clear_screen(ubyte color) {
if verafx.available() {
verafx.clear(0, 0, color, 320*240/4)
return
}
; fallback to cpu clear
cx16.VERA_CTRL=0
cx16.VERA_ADDR=0
cx16.VERA_ADDR_H = 1<<4 ; 1 pixel auto increment
repeat 240
cs_innerloop320(color)
repeat 240 {
%asm {{
lda p8v_color
ldy #320/8
- .rept 8
sta cx16.VERA_DATA0
.endrept
dey
bne -
}}
}
cx16.VERA_ADDR=0
cx16.VERA_ADDR_H = 0
}

asmsub plot(uword x @AX, ubyte y @Y, ubyte color @R0) {
; x in r0, y in r1, color.
%asm {{
clc
adc times320_lo,y
sta cx16.VERA_ADDR_L
txa
adc times320_mid,y
sta cx16.VERA_ADDR_M
lda #0
adc times320_hi,y
sta cx16.VERA_ADDR_H
lda cx16.r0L
sta cx16.VERA_DATA0
rts
}}
}

sub line(uword x1, ubyte y1, uword x2, ubyte y2, ubyte color) {
; Bresenham algorithm.
; This code special-cases various quadrant loops to allow simple ++ and -- operations.
Expand Down Expand Up @@ -133,7 +167,7 @@ gfx_lores {
}

asmsub plot() {
; x in r0, y in r1, color.
; internal plot routine for the line algorithm: x in r0, y in r1, color in variable.
%asm {{
ldy cx16.r1L
clc
Expand All @@ -151,23 +185,12 @@ gfx_lores {
rts
}}
}

%asm {{

; multiplication by 320 lookup table
times320 := 320*range(240)

times320_lo .byte <times320
times320_mid .byte >times320
times320_hi .byte `times320

}}
}

sub horizontal_line(uword xx, ubyte yy, uword length, ubyte color) {
if length==0
return
vera_setaddr(xx, yy)
plot(xx, yy, color) ; set starting position by reusing plot routine
; set vera auto-increment to 1 pixel
cx16.VERA_ADDR_H = cx16.VERA_ADDR_H & %00000111 | (1<<4)

Expand All @@ -191,45 +214,28 @@ times320_hi .byte `times320
}

sub vertical_line(uword xx, ubyte yy, ubyte lheight, ubyte color) {
vera_setaddr(xx,yy)
if lheight==0
return
plot(xx, yy, color) ; set starting position by reusing plot routine
; set vera auto-increment to 320 pixel increment (=next line)
cx16.VERA_ADDR_H = cx16.VERA_ADDR_H & %00000111 | (14<<4)
%asm {{
ldy p8v_lheight
beq +
lda p8v_color
- sta cx16.VERA_DATA0
dey
bne -
+
}}
}


asmsub cs_innerloop320(ubyte color @A) clobbers(Y) {
; using verafx 32 bits writes here would make this faster but it's safer to
; use verafx only explicitly when you know what you're doing.
%asm {{
ldy #40
- sta cx16.VERA_DATA0
sta cx16.VERA_DATA0
sta cx16.VERA_DATA0
sta cx16.VERA_DATA0
sta cx16.VERA_DATA0
sta cx16.VERA_DATA0
sta cx16.VERA_DATA0
sta cx16.VERA_DATA0
dey
bne -
rts
}}
}
%asm {{
; multiplication by 320 lookup table
times320 := 320*range(240)

inline asmsub vera_setaddr(uword xx @R0, ubyte yy @R1) {
; set the correct vera start address (no auto increment yet!)
%asm {{
jsr p8s_line.p8s_plot
}}
}
times320_lo .byte <times320
times320_mid .byte >times320
times320_hi .byte `times320
}}
}

13 changes: 7 additions & 6 deletions compiler/res/prog8lib/cx16/verafx.p8
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ verafx {

sub available() -> bool {
; returns true if Vera FX is available (Vera V0.3.1 or later), false if not.
cx16.r1L = 0
cx16.r0L = cx16.VERA_CTRL
cx16.r0H = 0
cx16.VERA_CTRL = $7e
if cx16.VERA_DC_VER0 == $56 {
; Vera version number is valid.
; Vera fx is available on Vera version 0.3.1 and later,
; so no need to even check VERA_DC_VER1, which contains 0 (or higher)
cx16.r1L = mkword(cx16.VERA_DC_VER2, cx16.VERA_DC_VER3) >= $0301 as ubyte
; Vera version number is valid. Vera fx is available on Vera version 0.3.1 and later.
if cx16.VERA_DC_VER1>0
cx16.r0H = 1
else
cx16.r0H = mkword(cx16.VERA_DC_VER2, cx16.VERA_DC_VER3) >= $0301 as ubyte
}
cx16.VERA_CTRL = cx16.r0L
return cx16.r1L as bool
return cx16.r0H as bool
}

sub clear(ubyte vbank, uword vaddr, ubyte data, uword num_longwords) {
Expand Down
4 changes: 4 additions & 0 deletions docs/source/todo.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
TODO
====

word starw
for starw in 50 downto 0 -> compiler error word loop variable can only loop over bytes or words


Regenerate skeleton doc files.

Improve register load order in subroutine call args assignments:
Expand Down
161 changes: 161 additions & 0 deletions syntax-files/SublimeText/Prog8.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
%YAML 1.2
---
# http://www.sublimetext.com/docs/syntax.html
name: prog8
file_extensions:
- p8
- prog8
scope: source.prog8
contexts:
main:
- include: comment
- include: meta
- match: '(^\s*\w+\s*)(\{)'
captures:
1: entity.name.namespace.prog8
2: punctuation.prog8
push:
- match: '(\})'
captures:
1: punctuation.prog8
pop: true
- include: main__1
- match: '(^\s*\w+\s*)(\$[\da-fA-F]+\s*)(\{)'
captures:
1: entity.name.namespace.prog8
2: constant.numeric.integer.hexadecimal.prog8
3: punctuation.prog8
push:
- match: '(\})'
captures:
1: punctuation.prog8
pop: true
- include: main__2
comment:
- match: (\;)(.+)
captures:
1: comment.line.prog8
2: comment.line.prog8
assembler:
- match: (\b(adc|and|asl|bcc|bcs|beq|bit|bmi|bne|bpl|brk|bvc|bvs|clc|cld|cli|clv|cmp|cpx|cpy|dec|dex|dey|eor|inc|inx|iny|jmp|jsr|lda|ldx|ldy|lsr|nop|ora|pha|php|pla|plp|rol|ror|rti|rts|sbc|sec|sed|sei|sta|stx|sty|tax|tay|tsx|txa|txs|tya|bra|brl|cop|jml|jsl|mvn|mvp|pea|pei|per|phb|phd|phk|phx|phy|plb|pld|plx|ply|rep|rtl|sep|stp|stz|tcd|tcs|tdc|trb|tsb|tsc|txy|tyx|wai|wdm|xba|xce|ADC|AND|ASL|BCC|BCS|BEQ|BIT|BMI|BNE|BPL|BRK|BVC|BVS|CLC|CLD|CLI|CLV|CMP|CPX|CPY|DEC|DEX|DEY|EOR|INC|INX|INY|JMP|JSR|LDA|LDX|LDY|LSR|NOP|ORA|PHA|PHP|PLA|PLP|ROL|ROR|RTI|RTS|SBC|SEC|SED|SEI|STA|STX|STY|TAX|TAY|TSX|TXA|TXS|TYA|BRA|BRL|COP|JML|JSL|MVN|MVP|PEA|PEI|PER|PHB|PHD|PHK|PHX|PHY|PLB|PLD|PLX|PLY|REP|RTL|SEP|STP|STZ|TCD|TCS|TDC|TRB|TSB|TSC|TXY|TYX|WAI|WDM|XBA|XCE)\b)
scope: support.function.prog8
constant:
- match: (\btrue|false|void\b)
scope: constant.language.prog8
general:
- match: '(^\s*)(\%asm)(\s*{{)'
captures:
1: punctuation.prog8
2: keyword.control.directive.prog8
3: punctuation.prog8
push:
- match: '(}})'
captures:
1: punctuation.prog8
pop: true
- include: general__1
- match: '(\{)'
captures:
1: punctuation.prog8
push:
- match: '(\})'
captures:
1: punctuation.prog8
pop: true
- include: general__2
- match: (\")
captures:
1: punctuation.prog8
push:
- meta_content_scope: text.prog8
- match: (\")
captures:
1: punctuation.prog8
pop: true
- match: (\()
captures:
1: punctuation.prog8
push:
- match: (\))
captures:
1: punctuation.prog8
pop: true
- include: general__4
- include: comment
- include: numeric
- include: keywords
- include: storage
- include: constant
- include: support
- include: label
- include: meta
- match: (\w+)(\s*)(\()
captures:
1: entity.name.function.prog8
2: punctuation.prog8
3: punctuation.prog8
push:
- match: (\))
captures:
1: punctuation.prog8
pop: true
- include: general__5
- include: section
- include: variable
general__1:
- include: assembler
- include: comment
- include: numeric
- include: label
- include: section
- include: variable
general__2:
- include: general
general__3: []
general__4:
- include: general
general__5:
- include: general
keywords:
- match: (\b(sub|if|if_cs|if_cc|if_eq|if_ne|if_pl|if_mi|if_vs|if_vc|if_z|if_nz|if_pos|if_neg|for|in|to|step|do|while|until|repeat|else|when|return|break|as|goto|asmsub|clobbers)\b)
scope: keyword.control.prog8
- match: (\b(and|or)\b)
scope: keyword.operator.prog8
label:
- match: (^\s*\w+\:)
scope: entity.name.label.prog8
main__1:
- include: general
main__2:
- include: general
meta:
- match: '(^\s*)(%)([a-zA-Z]+)'
captures:
1: punctuation.prog8
2: meta.directive.prog8
3: keyword.control.directive.prog8
numeric:
- match: (\b\d+)
scope: constant.numeric.integer.prog8
- match: (\-?\d+\.\d+e?\d+)
scope: constant.numeric.float.prog8
- match: '(\$[\da-fA-F]+)'
scope: constant.numeric.integer.hexadecimal.prog8
- match: '(\%[0-1]+)'
scope: constant.numeric.integer.binary.prog8
- match: (\'.\')
scope: constant.numeric.integer.prog8
section:
- match: (\b\w+\.)
scope: entity.name.namespace.prog8
storage:
- match: (\b(ubyte|byte|word|uword|float|str)\b)
scope: storage.type.prog8
- match: (\b(const)\b)
scope: storage.modifier.prog8
support:
- match: (\b(abs|atan|ceil|cos|cos8u|cos8|cos16u|cos16|deg|floor|ln|log2|rad|round|sin|sgn|sin8u|sin8|sin16u|sin16|sqrt16|sqrt|tan|any|all|len|max|min|reverse|sum|sort|memcopy|memset|memsetw|leftstr|rightstr|strlen|strcmp|substr|exit|lsb|msb|mkword|rnd|rndw|rndf|rol|rol2|ror|ror2|rsave|rrestore|read_flags|sizeof|set_carry|clear_carry|set_irqd|clear_irqd|swap)\b)
scope: support.function.prog8
variable:
- match: (\b\w+\b)
scope: variable.other.prog8
9 changes: 6 additions & 3 deletions syntax-files/SublimeText/readme.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
We need a new syntax file for Sublime Text.
Here is a ".sublime-syntax" syntax file for Sublime Text 4.
Format: see https://www.sublimetext.com/docs/syntax.html

This file can also be used for other tools as well, such as 'bat':
https://github.com/sharkdp/bat
https://github.com/sharkdp/bat?tab=readme-ov-file#adding-new-syntaxes--language-definitions

The old (no longer functioning) syntax definition file can be found here:

https://github.com/akubiczek/Prog8-TmLanguage-VsCode/tree/master/sublime3
The older "tmLanguage" syntax definition file, where this sublime-syntax version is based on, can still be found here:

https://github.com/akubiczek/Prog8-TmLanguage-VsCode/tree/master/sublime3

0 comments on commit c13168b

Please sign in to comment.