prog8/examples/sorting.p8

70 lines
1.3 KiB
Plaintext
Raw Normal View History

%import textio
2019-08-17 23:39:48 +00:00
%zeropage basicsafe
; Note: this program is compatible with C64 and CX16.
2019-08-17 23:39:48 +00:00
main {
sub start() {
ubyte[] uba = [10,0,2,8,5,4,3,9]
uword[] uwa = [1000,0,200,8000,50,40000,3,900]
byte[] ba = [-10,0,-2,8,5,4,-3,9,-99]
word[] wa = [-1000,0,-200,8000,50,31111,3,-900]
2020-08-27 16:10:22 +00:00
txt.print("original\n")
2019-08-17 23:39:48 +00:00
print_arrays()
sort(uba)
sort(uwa)
sort(ba)
sort(wa)
2020-08-27 16:10:22 +00:00
txt.print("sorted\n")
2019-08-17 23:39:48 +00:00
print_arrays()
reverse(uba)
reverse(uwa)
reverse(ba)
reverse(wa)
2020-08-27 16:10:22 +00:00
txt.print("reversed\n")
2019-08-17 23:39:48 +00:00
print_arrays()
2020-11-22 17:17:43 +00:00
;test_stack.test()
2019-08-17 23:39:48 +00:00
return
sub print_arrays() {
ubyte ub
uword uw
byte bb
word ww
for ub in uba {
2020-08-27 16:10:22 +00:00
txt.print_ub(ub)
txt.chrout(',')
2019-08-17 23:39:48 +00:00
}
2021-01-08 15:56:17 +00:00
txt.nl()
2019-08-17 23:39:48 +00:00
for uw in uwa {
2020-08-27 16:10:22 +00:00
txt.print_uw(uw)
txt.chrout(',')
2019-08-17 23:39:48 +00:00
}
2021-01-08 15:56:17 +00:00
txt.nl()
2019-08-17 23:39:48 +00:00
for bb in ba {
2020-08-27 16:10:22 +00:00
txt.print_b(bb)
txt.chrout(',')
2019-08-17 23:39:48 +00:00
}
2021-01-08 15:56:17 +00:00
txt.nl()
2019-08-17 23:39:48 +00:00
for ww in wa {
2020-08-27 16:10:22 +00:00
txt.print_w(ww)
txt.chrout(',')
2019-08-17 23:39:48 +00:00
}
2021-01-08 15:56:17 +00:00
txt.nl()
txt.nl()
2019-08-17 23:39:48 +00:00
}
}
}