use bool type in examples and libraries

This commit is contained in:
Irmen de Jong 2022-07-08 21:50:32 +02:00
parent 81b3d2db4f
commit 8acb37b6c2
13 changed files with 59 additions and 59 deletions

View File

@ -28,7 +28,7 @@ gfx2 {
uword width = 0 uword width = 0
uword height = 0 uword height = 0
ubyte bpp = 0 ubyte bpp = 0
ubyte monochrome_dont_stipple_flag = false ; set to false to enable stippling mode in monochrome displaymodes bool monochrome_dont_stipple_flag = false ; set to false to enable stippling mode in monochrome displaymodes
sub screen_mode(ubyte mode) { sub screen_mode(ubyte mode) {
when mode { when mode {
@ -127,7 +127,7 @@ gfx2 {
position(0, 0) position(0, 0)
} }
sub monochrome_stipple(ubyte enable) { sub monochrome_stipple(bool enable) {
monochrome_dont_stipple_flag = not enable monochrome_dont_stipple_flag = not enable
} }
@ -683,7 +683,7 @@ _done
} }
} }
sub position2(uword @zp x, uword y, ubyte also_port_1) { sub position2(uword @zp x, uword y, bool also_port_1) {
position(x, y) position(x, y)
if also_port_1 { if also_port_1 {
when active_mode { when active_mode {

View File

@ -6,7 +6,7 @@
diskio { diskio {
sub directory(ubyte drivenumber) -> ubyte { sub directory(ubyte drivenumber) -> bool {
; -- Prints the directory contents of disk drive 8-11 to the screen. Returns success. ; -- Prints the directory contents of disk drive 8-11 to the screen. Returns success.
c64.SETNAM(1, "$") c64.SETNAM(1, "$")
@ -61,12 +61,12 @@ io_error:
; internal variables for the iterative file lister / loader ; internal variables for the iterative file lister / loader
ubyte list_skip_disk_name bool list_skip_disk_name
uword list_pattern uword list_pattern
uword list_blocks uword list_blocks
ubyte iteration_in_progress = false bool iteration_in_progress = false
ubyte @zp first_byte ubyte @zp first_byte
ubyte have_first_byte bool have_first_byte
str list_filename = "?" * 32 str list_filename = "?" * 32
@ -98,7 +98,7 @@ io_error:
; ----- iterative file lister functions (uses io channel 12) ----- ; ----- iterative file lister functions (uses io channel 12) -----
sub lf_start_list(ubyte drivenumber, uword pattern_ptr) -> ubyte { sub lf_start_list(ubyte drivenumber, uword pattern_ptr) -> bool {
; -- start an iterative file listing with optional pattern matching. ; -- start an iterative file listing with optional pattern matching.
; note: only a single iteration loop can be active at a time! ; note: only a single iteration loop can be active at a time!
lf_end_list() lf_end_list()
@ -127,7 +127,7 @@ io_error:
return false return false
} }
sub lf_next_entry() -> ubyte { sub lf_next_entry() -> bool {
; -- retrieve the next entry from an iterative file listing session. ; -- retrieve the next entry from an iterative file listing session.
; results will be found in list_blocks and list_filename. ; results will be found in list_blocks and list_filename.
; if it returns false though, there are no more entries (or an error occurred). ; if it returns false though, there are no more entries (or an error occurred).
@ -199,7 +199,7 @@ close_end:
; ----- iterative file loader functions (uses io channel 11) ----- ; ----- iterative file loader functions (uses io channel 11) -----
sub f_open(ubyte drivenumber, uword filenameptr) -> ubyte { sub f_open(ubyte drivenumber, uword filenameptr) -> bool {
; -- open a file for iterative reading with f_read ; -- open a file for iterative reading with f_read
; note: only a single iteration loop can be active at a time! ; note: only a single iteration loop can be active at a time!
f_close() f_close()
@ -343,7 +343,7 @@ _end rts
; ----- iterative file saver functions (uses io channel 14) ----- ; ----- iterative file saver functions (uses io channel 14) -----
sub f_open_w(ubyte drivenumber, uword filenameptr) -> ubyte { sub f_open_w(ubyte drivenumber, uword filenameptr) -> bool {
; -- open a file for iterative writing with f_write ; -- open a file for iterative writing with f_write
f_close_w() f_close_w()
@ -358,7 +358,7 @@ _end rts
return false return false
} }
sub f_write(uword bufferpointer, uword num_bytes) -> ubyte { sub f_write(uword bufferpointer, uword num_bytes) -> bool {
; -- write the given umber of bytes to the currently open file ; -- write the given umber of bytes to the currently open file
if num_bytes!=0 { if num_bytes!=0 {
void c64.CHKOUT(14) ; use #14 as input channel again void c64.CHKOUT(14) ; use #14 as input channel again
@ -408,7 +408,7 @@ io_error:
goto done goto done
} }
sub save(ubyte drivenumber, uword filenameptr, uword address, uword size) -> ubyte { sub save(ubyte drivenumber, uword filenameptr, uword address, uword size) -> bool {
c64.SETNAM(string.length(filenameptr), filenameptr) c64.SETNAM(string.length(filenameptr), filenameptr)
c64.SETLFS(1, drivenumber, 0) c64.SETLFS(1, drivenumber, 0)
uword @shared end_address = address + size uword @shared end_address = address + size
@ -478,7 +478,7 @@ io_error:
; Internal routine, only to be used on Commander X16 platform if headerless=true, ; Internal routine, only to be used on Commander X16 platform if headerless=true,
; because this routine uses kernal support for that to load headerless files. ; because this routine uses kernal support for that to load headerless files.
sub load_headerless_cx16(ubyte drivenumber, uword filenameptr, uword address_override, ubyte headerless) -> uword { sub load_headerless_cx16(ubyte drivenumber, uword filenameptr, uword address_override, bool headerless) -> uword {
c64.SETNAM(string.length(filenameptr), filenameptr) c64.SETNAM(string.length(filenameptr), filenameptr)
ubyte secondary = 1 ubyte secondary = 1
cx16.r1 = 0 cx16.r1 = 0

View File

@ -53,7 +53,7 @@ main {
repeat { repeat {
ubyte current_question = 1 ubyte current_question = 1
txt.print("\n\nanimal guessing game!\nthink of an animal.\n") txt.print("\n\nanimal guessing game!\nthink of an animal.\n")
ubyte guessed = false bool guessed = false
while not guessed { while not guessed {
txt.print(questions[current_question]) txt.print(questions[current_question])
txt.print("? ") txt.print("? ")

View File

@ -26,7 +26,7 @@ main {
ubyte target_height = 10 ubyte target_height = 10
ubyte active_height = 24 ubyte active_height = 24
ubyte upwards = true bool upwards = true
repeat { repeat {
;txt.plot(0,0) ;txt.plot(0,0)

View File

@ -11,8 +11,8 @@ main {
ubyte[255] BX ubyte[255] BX
ubyte[255] BY ubyte[255] BY
ubyte[255] BC ubyte[255] BC
ubyte[255] DX bool[255] DX
ubyte[255] DY bool[255] DY
txt.print("number of balls (1-255)? ") txt.print("number of balls (1-255)? ")
void txt.input_chars(input) void txt.input_chars(input)
@ -37,28 +37,28 @@ main {
; Clear existing Location the ball is at ; Clear existing Location the ball is at
txt.setclr(BX[lp], BY[lp], 0) txt.setclr(BX[lp], BY[lp], 0)
if DX[lp] == 0 { if not DX[lp] {
if (BX[lp] == 0) if (BX[lp] == 0)
DX[lp] = 1 DX[lp] = true
else else
BX[lp]=BX[lp]-1 BX[lp]=BX[lp]-1
} else if DX[lp] == 1 { } else if DX[lp] {
if (BX[lp] == txt.DEFAULT_WIDTH-1) { if (BX[lp] == txt.DEFAULT_WIDTH-1) {
BX[lp] = txt.DEFAULT_WIDTH-2 BX[lp] = txt.DEFAULT_WIDTH-2
DX[lp] = 0 DX[lp] = false
} else { } else {
BX[lp]=BX[lp]+1 BX[lp]=BX[lp]+1
} }
} }
if DY[lp] == 0 { if not DY[lp] {
if (BY[lp] == 0) if (BY[lp] == 0)
DY[lp] = 1 DY[lp] = true
else else
BY[lp]=BY[lp]-1 BY[lp]=BY[lp]-1
} else if DY[lp] == 1 { } else if DY[lp] == 1 {
if (BY[lp] == txt.DEFAULT_HEIGHT-1) { if (BY[lp] == txt.DEFAULT_HEIGHT-1) {
BY[lp] = txt.DEFAULT_HEIGHT-2 BY[lp] = txt.DEFAULT_HEIGHT-2
DY[lp] = 0 DY[lp] = false
} else { } else {
BY[lp]=BY[lp]+1 BY[lp]=BY[lp]+1
} }

View File

@ -103,7 +103,7 @@ main {
widget { widget {
sub highlightedrect(uword x, uword y, uword width, uword height, ubyte fill, ubyte active) { sub highlightedrect(uword x, uword y, uword width, uword height, bool fill, bool active) {
gfx2.horizontal_line(x, y, width, 2) gfx2.horizontal_line(x, y, width, 2)
gfx2.vertical_line(x, y+1, height-1, 2) gfx2.vertical_line(x, y+1, height-1, 2)
gfx2.vertical_line(x+width-1, y+1, height-1, 1) gfx2.vertical_line(x+width-1, y+1, height-1, 1)
@ -128,7 +128,7 @@ widget {
} }
sub window_titlebar(uword x, uword y, uword width, uword titlestr, ubyte active) { sub window_titlebar(uword x, uword y, uword width, uword titlestr, bool active) {
const ubyte height = 11 const ubyte height = 11
widget.highlightedrect(x+widget.window_close_icon.width, y, width-64, height, true, active) widget.highlightedrect(x+widget.window_close_icon.width, y, width-64, height, true, active)
gfx2.plot(x+widget.window_close_icon.width, y+height-1, 1) ; correct bottom left corner gfx2.plot(x+widget.window_close_icon.width, y+height-1, 1) ; correct bottom left corner
@ -138,7 +138,7 @@ widget {
widget.window_flipsize_icon(x+width-44, y, active) widget.window_flipsize_icon(x+width-44, y, active)
} }
sub window_flipsize_icon(uword x, uword y, ubyte active) { sub window_flipsize_icon(uword x, uword y, bool active) {
const uword width = 22 const uword width = 22
const uword height = 11 const uword height = 11
highlightedrect(x, y, width, height, true, active) highlightedrect(x, y, width, height, true, active)
@ -148,7 +148,7 @@ widget {
gfx2.fillrect(x+6, y+3, 5, 2, 2) gfx2.fillrect(x+6, y+3, 5, 2, 2)
} }
sub window_order_icon(uword x, uword y, ubyte active) { sub window_order_icon(uword x, uword y, bool active) {
const uword width = 22 const uword width = 22
const uword height = 11 const uword height = 11
highlightedrect(x, y, width, height, true, active) highlightedrect(x, y, width, height, true, active)
@ -158,7 +158,7 @@ widget {
gfx2.rect(x+8, y+4, 10, 5, 1) ; front gfx2.rect(x+8, y+4, 10, 5, 1) ; front
} }
sub window_close_icon(uword x, uword y, ubyte active) { sub window_close_icon(uword x, uword y, bool active) {
const uword width = 20 const uword width = 20
const uword height = 11 const uword height = 11
highlightedrect(x, y, width, height, true, active) highlightedrect(x, y, width, height, true, active)
@ -167,7 +167,7 @@ widget {
gfx2.fillrect(x+8, y+4, 3, 3, 2) gfx2.fillrect(x+8, y+4, 3, 3, 2)
} }
sub window_leftborder(uword x, uword y, uword height, ubyte active) { sub window_leftborder(uword x, uword y, uword height, bool active) {
gfx2.vertical_line(x, y, height, 2) gfx2.vertical_line(x, y, height, 2)
ubyte color = 0 ubyte color = 0
if active if active
@ -181,7 +181,7 @@ widget {
gfx2.horizontal_line(x, y+height-1, width, 1) gfx2.horizontal_line(x, y+height-1, width, 1)
} }
sub window_rightborder(uword x, uword y, uword width, uword height, ubyte active) { sub window_rightborder(uword x, uword y, uword width, uword height, bool active) {
gfx2.vertical_line(x+width-1-16, y+11, height-13,2) gfx2.vertical_line(x+width-1-16, y+11, height-13,2)
gfx2.vertical_line(x+width-1, y+11, height-11,1) gfx2.vertical_line(x+width-1, y+11, height-11,1)
ubyte color = 0 ubyte color = 0

View File

@ -186,7 +186,7 @@ _ones pla
} }
} }
sub facing_away(ubyte edgePointsIdx) -> ubyte { sub facing_away(ubyte edgePointsIdx) -> bool {
; simplistic visibility determination by checking the Z component of the surface normal ; simplistic visibility determination by checking the Z component of the surface normal
; TODO: actually take the line of sight vector into account ; TODO: actually take the line of sight vector into account
ubyte p1 = shipdata.facesPoints[edgePointsIdx] ubyte p1 = shipdata.facesPoints[edgePointsIdx]

View File

@ -13,7 +13,7 @@ main {
cx16.KEYHDL = &main.keyboard_scancode_handler.asm_shim cx16.KEYHDL = &main.keyboard_scancode_handler.asm_shim
sys.clear_irqd() sys.clear_irqd()
ubyte escape_pressed bool escape_pressed
while not escape_pressed { while not escape_pressed {
; just sit here ; just sit here
} }
@ -22,7 +22,7 @@ main {
sys.clear_irqd() sys.clear_irqd()
} }
sub keyboard_scancode_handler(ubyte prefix, ubyte scancode, ubyte updown) { sub keyboard_scancode_handler(ubyte prefix, ubyte scancode, bool updown) {
txt.print_ubhex(prefix, true) txt.print_ubhex(prefix, true)
txt.chrout(':') txt.chrout(':')
txt.print_ubhex(scancode, true) txt.print_ubhex(scancode, true)

View File

@ -27,7 +27,7 @@ main {
ubyte nextBlock ubyte nextBlock
ubyte speedlevel ubyte speedlevel
ubyte holding ubyte holding
ubyte holdingAllowed bool holdingAllowed
sub start() { sub start() {
@ -390,7 +390,7 @@ waitkey:
} }
} }
sub drawBlock(ubyte x, ubyte y, ubyte erase) { sub drawBlock(ubyte x, ubyte y, bool erase) {
ubyte char = 79 ; top left edge ubyte char = 79 ; top left edge
if erase if erase
char = 32 ; space char = 32 ; space
@ -538,21 +538,21 @@ blocklogic {
; The full play area is bordered by (in)visible characters that will collide. ; The full play area is bordered by (in)visible characters that will collide.
; Collision is determined by reading the screen data directly. ; Collision is determined by reading the screen data directly.
sub canRotateCW(ubyte xpos, ubyte ypos) -> ubyte { sub canRotateCW(ubyte xpos, ubyte ypos) -> bool {
rotateCW() rotateCW()
ubyte nocollision = noCollision(xpos, ypos) bool nocollision = noCollision(xpos, ypos)
rotateCCW() rotateCCW()
return nocollision return nocollision
} }
sub canRotateCCW(ubyte xpos, ubyte ypos) -> ubyte { sub canRotateCCW(ubyte xpos, ubyte ypos) -> bool {
rotateCCW() rotateCCW()
ubyte nocollision = noCollision(xpos, ypos) bool nocollision = noCollision(xpos, ypos)
rotateCW() rotateCW()
return nocollision return nocollision
} }
sub noCollision(ubyte xpos, ubyte ypos) -> ubyte { sub noCollision(ubyte xpos, ubyte ypos) -> bool {
ubyte @zp i ubyte @zp i
for i in 15 downto 0 { for i in 15 downto 0 {
if currentBlock[i] and txt.getchr(xpos + (i&3), ypos+i/4)!=32 if currentBlock[i] and txt.getchr(xpos + (i&3), ypos+i/4)!=32
@ -561,14 +561,14 @@ blocklogic {
return true return true
} }
sub isGameOver(ubyte xpos, ubyte ypos) -> ubyte { sub isGameOver(ubyte xpos, ubyte ypos) -> bool {
main.drawBlock(xpos, ypos, true) main.drawBlock(xpos, ypos, true)
ubyte result = ypos==main.startYpos and not noCollision(xpos, ypos+1) bool result = ypos==main.startYpos and not noCollision(xpos, ypos+1)
main.drawBlock(xpos, ypos, false) main.drawBlock(xpos, ypos, false)
return result return result
} }
sub isLineFull(ubyte ypos) -> ubyte { sub isLineFull(ubyte ypos) -> bool {
ubyte x ubyte x
for x in main.boardOffsetX to main.boardOffsetX+main.boardWidth-1 { for x in main.boardOffsetX to main.boardOffsetX+main.boardWidth-1 {
if txt.getchr(x, ypos)==32 if txt.getchr(x, ypos)==32

View File

@ -6,7 +6,7 @@
main { main {
ubyte[256] sieve bool[256] sieve
ubyte candidate_prime = 2 ; is increased in the loop ubyte candidate_prime = 2 ; is increased in the loop
sub start() { sub start() {

View File

@ -1,17 +1,17 @@
%import textio %import textio
%zeropage basicsafe %zeropage basicsafe
main {
bool[] barray = [true, false, 1, 0, 222] main {
sub noCollision(ubyte xpos, ubyte ypos) -> bool {
if xpos
return false
else
return true
}
sub start() { sub start() {
bool bb bool z=noCollision(1,2)
ubyte xx }
for bb in barray {
if bb
xx++
}
}
} }

View File

@ -488,7 +488,7 @@ galaxy {
travel_to(number, current_planet) travel_to(number, current_planet)
} }
sub starmap(ubyte local) { sub starmap(bool local) {
ubyte current_planet = planet.number ubyte current_planet = planet.number
ubyte px = planet.x ubyte px = planet.x
ubyte py = planet.y ubyte py = planet.y
@ -908,7 +908,7 @@ planet {
} }
} }
sub display(ubyte compressed, ubyte distance) { sub display(bool compressed, ubyte distance) {
if compressed { if compressed {
print_name_uppercase() print_name_uppercase()
if distance { if distance {

View File

@ -30,7 +30,7 @@ turtle {
float xpos float xpos
float ypos float ypos
float angle float angle
ubyte pendown bool pendown
sub init() { sub init() {
xpos = 160.0 xpos = 160.0