Updated libsc.c65 and added multdivlib demo
This commit is contained in:
parent
a15d45a130
commit
930e81573a
4 changed files with 184 additions and 0 deletions
3
examples/multdivlib_demo/cm.sh
Normal file
3
examples/multdivlib_demo/cm.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
PROGNAME="multdivlib_demo"
|
||||||
|
c65gm ${PROGNAME}.c65
|
||||||
168
examples/multdivlib_demo/multdivlib_demo.c65
Normal file
168
examples/multdivlib_demo/multdivlib_demo.c65
Normal file
|
|
@ -0,0 +1,168 @@
|
||||||
|
//-----------------------------------------------------------
|
||||||
|
// MultDiv Library Demo
|
||||||
|
// Demonstrates multiplication and division routines
|
||||||
|
//-----------------------------------------------------------
|
||||||
|
|
||||||
|
#INCLUDE <c64start.c65>
|
||||||
|
#INCLUDE <c64defs.c65>
|
||||||
|
#INCLUDE <multdivlib.c65>
|
||||||
|
#INCLUDE <cbmiolib.c65>
|
||||||
|
|
||||||
|
#PRAGMA _P_USE_CBM_STRINGS 1
|
||||||
|
|
||||||
|
GOTO start
|
||||||
|
|
||||||
|
WORD high
|
||||||
|
BYTE i
|
||||||
|
|
||||||
|
//-----------------------------------------------------------
|
||||||
|
// Wait for key
|
||||||
|
//-----------------------------------------------------------
|
||||||
|
FUNC wait_key
|
||||||
|
BYTE key
|
||||||
|
|
||||||
|
WHILE 1
|
||||||
|
key = PEEK $c5
|
||||||
|
IF key = 64
|
||||||
|
BREAK
|
||||||
|
ENDIF
|
||||||
|
WEND
|
||||||
|
|
||||||
|
WHILE 1
|
||||||
|
key = PEEK $c5
|
||||||
|
IF key != 64
|
||||||
|
BREAK
|
||||||
|
ENDIF
|
||||||
|
WEND
|
||||||
|
|
||||||
|
POKE $c6 WITH 0
|
||||||
|
FEND
|
||||||
|
|
||||||
|
//-----------------------------------------------------------
|
||||||
|
// Main demo
|
||||||
|
//-----------------------------------------------------------
|
||||||
|
FUNC main
|
||||||
|
|
||||||
|
lib_cbmio_cls()
|
||||||
|
|
||||||
|
lib_cbmio_printlf("multdivlib demo")
|
||||||
|
lib_cbmio_printlf("===============")
|
||||||
|
lib_cbmio_lf()
|
||||||
|
|
||||||
|
WORD a
|
||||||
|
WORD b
|
||||||
|
|
||||||
|
//-----------------------------------------
|
||||||
|
// Test 1: mult - 123 * 456 (16-bit result)
|
||||||
|
// io:lib_multdiv_acc is input/output
|
||||||
|
// result in lib_multdiv_acc, high in lib_multdiv_ext
|
||||||
|
//-----------------------------------------
|
||||||
|
lib_cbmio_printlf("lib_multdiv_mult: 123 * 456 =")
|
||||||
|
|
||||||
|
a = 123
|
||||||
|
b = 456
|
||||||
|
lib_multdiv_mult(a, b)
|
||||||
|
|
||||||
|
lib_cbmio_print(" result: ")
|
||||||
|
lib_cbmio_hexoutw(lib_multdiv_acc)
|
||||||
|
lib_cbmio_lf()
|
||||||
|
lib_cbmio_lf()
|
||||||
|
|
||||||
|
lib_cbmio_print("press any key...")
|
||||||
|
wait_key()
|
||||||
|
lib_cbmio_lf()
|
||||||
|
lib_cbmio_lf()
|
||||||
|
|
||||||
|
//-----------------------------------------
|
||||||
|
// Test 2: mult32 - 65000 * 100 (32-bit result)
|
||||||
|
// out:high gets the high word
|
||||||
|
//-----------------------------------------
|
||||||
|
lib_cbmio_printlf("mult32: 65000 * 100 =")
|
||||||
|
|
||||||
|
a = 65000
|
||||||
|
b = 100
|
||||||
|
lib_multdiv_mult32(a, b, high)
|
||||||
|
|
||||||
|
lib_cbmio_print(" low: $")
|
||||||
|
lib_cbmio_hexoutw(lib_multdiv_acc)
|
||||||
|
lib_cbmio_print(" high: $")
|
||||||
|
lib_cbmio_hexoutw(high)
|
||||||
|
lib_cbmio_lf()
|
||||||
|
lib_cbmio_lf()
|
||||||
|
|
||||||
|
lib_cbmio_print("press any key...")
|
||||||
|
wait_key()
|
||||||
|
lib_cbmio_lf()
|
||||||
|
lib_cbmio_lf()
|
||||||
|
|
||||||
|
//-----------------------------------------
|
||||||
|
// Test 3: div - 1337 / 7
|
||||||
|
// quotient in lib_multdiv_acc, remainder in lib_multdiv_ext
|
||||||
|
//-----------------------------------------
|
||||||
|
lib_cbmio_printlf("lib_multdiv_div: 1337 / 7 =")
|
||||||
|
|
||||||
|
a = 1337
|
||||||
|
b = 7
|
||||||
|
lib_multdiv_div(a, b)
|
||||||
|
|
||||||
|
lib_cbmio_print(" quotient: ")
|
||||||
|
lib_cbmio_hexoutw(lib_multdiv_acc)
|
||||||
|
lib_cbmio_lf()
|
||||||
|
|
||||||
|
lib_cbmio_print(" remainder: ")
|
||||||
|
lib_cbmio_hexoutw(lib_multdiv_ext)
|
||||||
|
lib_cbmio_lf()
|
||||||
|
lib_cbmio_lf()
|
||||||
|
|
||||||
|
//-----------------------------------------
|
||||||
|
// Test 4: divmod - 1000 / 13
|
||||||
|
// out:high gets the remainder
|
||||||
|
//-----------------------------------------
|
||||||
|
lib_cbmio_printlf("divmod: 1000 / 13 =")
|
||||||
|
|
||||||
|
a = 1000
|
||||||
|
b = 13
|
||||||
|
lib_multdiv_divmod(a, b, high)
|
||||||
|
|
||||||
|
lib_cbmio_print(" quotient: ")
|
||||||
|
lib_cbmio_hexoutw(lib_multdiv_acc)
|
||||||
|
lib_cbmio_lf()
|
||||||
|
|
||||||
|
lib_cbmio_print(" remainder: $")
|
||||||
|
lib_cbmio_hexoutw(high)
|
||||||
|
lib_cbmio_lf()
|
||||||
|
lib_cbmio_lf()
|
||||||
|
|
||||||
|
lib_cbmio_print("press any key...")
|
||||||
|
wait_key()
|
||||||
|
lib_cbmio_lf()
|
||||||
|
lib_cbmio_lf()
|
||||||
|
|
||||||
|
//-----------------------------------------
|
||||||
|
// Test 5: Loop 0-9 multiplied by 10
|
||||||
|
//-----------------------------------------
|
||||||
|
lib_cbmio_printlf("loop: 0*10 through 9*10:")
|
||||||
|
lib_cbmio_lf()
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
WHILE i < 10
|
||||||
|
a = i
|
||||||
|
b = 10
|
||||||
|
lib_multdiv_mult(a, b)
|
||||||
|
|
||||||
|
lib_cbmio_print(" ")
|
||||||
|
lib_cbmio_hexoutb(i)
|
||||||
|
lib_cbmio_print(" * 10 = ")
|
||||||
|
lib_cbmio_hexoutw(lib_multdiv_acc)
|
||||||
|
lib_cbmio_lf()
|
||||||
|
|
||||||
|
i++
|
||||||
|
WEND
|
||||||
|
lib_cbmio_lf()
|
||||||
|
|
||||||
|
lib_cbmio_printlf("done!")
|
||||||
|
FEND
|
||||||
|
|
||||||
|
LABEL start
|
||||||
|
main()
|
||||||
|
SUBEND
|
||||||
2
examples/multdivlib_demo/start_in_vice.sh
Normal file
2
examples/multdivlib_demo/start_in_vice.sh
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
x64 -autostartprgmode 1 multdivlib_demo.prg
|
||||||
|
|
@ -45,6 +45,9 @@
|
||||||
#DEFINE memset = lib_string_memset
|
#DEFINE memset = lib_string_memset
|
||||||
#DEFINE strcat = lib_string_strcat
|
#DEFINE strcat = lib_string_strcat
|
||||||
#DEFINE strncat = lib_string_strncat
|
#DEFINE strncat = lib_string_strncat
|
||||||
|
#DEFINE strstr = lib_string_strstr
|
||||||
|
#DEFINE memcmp = lib_string_memcmp
|
||||||
|
#DEFINE memcpy = lib_string_memcpy
|
||||||
#IFEND
|
#IFEND
|
||||||
|
|
||||||
#IFDEF __LIB_STRLIST
|
#IFDEF __LIB_STRLIST
|
||||||
|
|
@ -62,6 +65,14 @@
|
||||||
#IFDEF __LIB_MEM
|
#IFDEF __LIB_MEM
|
||||||
#DEFINE malloc = lib_mem_malloc
|
#DEFINE malloc = lib_mem_malloc
|
||||||
#DEFINE free = lib_mem_free
|
#DEFINE free = lib_mem_free
|
||||||
|
#DEFINE mem_init = lib_mem_init
|
||||||
|
#DEFINE mem_defrag = lib_mem_defrag
|
||||||
|
#DEFINE mem_stats = lib_mem_stats
|
||||||
|
#IFEND
|
||||||
|
|
||||||
|
#IFDEF __LIB_MULTDIV
|
||||||
|
#DEFINE mult32 = lib_multdiv_mult32
|
||||||
|
#DEFINE divmod = lib_multdiv_divmod
|
||||||
#IFEND
|
#IFEND
|
||||||
|
|
||||||
#IFEND
|
#IFEND
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue