07-09-2022, 12:20 AM
(This post was last modified: 07-09-2022, 12:34 AM by fatman2021.)
@All
The QB64 runtime port is being done in FreeBASIC with custom pre-processor code:
The QB64 runtime port is being done in FreeBASIC with custom pre-processor code:
Code: (Select All)
#define FBCALL
#if defined(__FB_DOS__)
#include once "MBOOT.BI"
' Flags accepted by Screen and ScreenRes
'
' Usage examples:
' SCREEN 14, 16,, GFX_FULLSCREEN
' SCREEN 18, 32,, GFX_OPENGL OR GFX_STENCIL_BUFFER
'
#define GFX_NULL -1
#define GFX_WINDOWED &H00
#define GFX_FULLSCREEN &H01
#define GFX_OPENGL &H02
#define GFX_NO_SWITCH &H04
#define GFX_NO_FRAME &H08
#define GFX_SHAPED_WINDOW &H10
#define GFX_ALWAYS_ON_TOP &H20
#define GFX_ALPHA_PRIMITIVES &H40
#define GFX_HIGH_PRIORITY &H80
#define GFX_SCREEN_EXIT &H80000000l
#else
#include once "fbgfx.bi"
#include once "./src/kernel/include/multiboot.bi"
using FB
#endif
static shared as multiboot_info ptr MB_INFO
#if defined(__FB_DOS__)
#include once "ADRR.BI"
#else
#include once "address.bi"
#endif
#if defined(__FB_DOS__) or defined(__FB_WIN32__) or defined(__FB_WIN64__)
#define SYSTEM_TYPE ulongint
#else
#define SYSTEM_TYPE double
#endif
#if defined(__FB_DOS__)
'Ring 3 - c64dvd
static shared as SYSTEM_TYPE mem64 (01048575) ' Ram
#elseif defined(__FB_WIN32__) or defined(__WIN64__)
'Ring 3 - c64dvd
static shared as SYSTEM_TYPE mem64 (04194303) ' Ram
#else
'Ring 3 - c64dvd
static shared as SYSTEM_TYPE mem64 (16777215) ' Ram
#endif
#include once "qb64.bi"
/'
#if defined(__FB_LINUX__) or defined(__FB_CYGWIN__) or defined(__FB_FREEBSD__) or defined(__FB_NETBSD__) or _
defined(__FB_OPENBSD__) or defined(__FB_DARWIN__) or defined(__FB_XBOX__) or defined(__FB_UNIX__) or _
defined(__FB_64BIT__) or defined(__FB_ARM__)
#define I_INT &H4A2DC8
#define C_INT &H482C98
#define N0000 &H4A2DA0
#define N0001 &H4A2DA1
#define N0010 &H4A2DA2
#define N0011 &H4A2DA3
#define N0100 &H4A2DA4
#define N0101 &H4A2DA5
#define N0110 &H4A2DA6
#define N0111 &H4A2DA7
#define N1000 &H4A2DA8
#define N1001 &H4A2DA9
#define N1010 &H4A2DAA
#define N1011 &H4A2DAB
#define N1100 &H4A2DAC
#define N1101 &H4A2DAD
#define N1110 &H4A2DAE
#define N1111 &H4A2DAF
#endif
#if defined(__FB_DOS__)
#define I_INT &H1239D0
#define C_INT &H7719C
#define N0000 &H1239E8
#define N0001 &H1239E9
#define N0010 &H1239EA
#define N0011 &H1239EB
#define N0100 &H1239EC
#define N0101 &H1239ED
#define N0110 &H1239EE
#define N0111 &H1239EF
#define N1000 &H1239F0
#define N1001 &H1239F1
#define N1010 &H1239F2
#define N1011 &H1239F3
#define N1100 &H1239F4
#define N1101 &H1239F5
#define N1110 &H1239F6
#define N1111 &H1239F7
#endif
#if defined(__FB_WIN32__)
#define I_INT &H495DC8
#define C_INT &H475C98
#define N0000 &H513688
#define N0001 &H513689
#define N0010 &H51368A
#define N0011 &H51368B
#define N0100 &H51368C
#define N0101 &H51368D
#define N0110 &H51368E
#define N0111 &H51368F
#define N1000 &H513690
#define N1001 &H513691
#define N1010 &H513692
#define N1011 &H513693
#define N1100 &H513694
#define N1101 &H513695
#define N1110 &H513696
#define N1111 &H513697
#endif
'/
'#define M_PI 3.1415926535897932384626433832795028
#ifdef _DEBUG
# define dprint(msg) open err for output as #99:print #99,"debug: " & msg:close #99
#else
# define dprint(msg) :
#endif
'TCL keywords
#define proc function
'Python keywords
#define def sub
#define in
#define range(x, y) x to y
'Assembly Mnemonics
#define equ = 'Equal
#define add + 'Add
#define subt - 'Subtract
#define mul * 'Multiply
#define ndiv / 'Divide
#define idiv \ 'Integer Devide
#define expt ^ 'Exponentiate
#define neg - 'Negate
#define mov(x, y) x equ y 'Move
#define jmp goto 'Jump
#define cmp if 'Compare
#define eq = 'Equal
#define ne <> 'Not equal
#define lt < 'Less than
#define ls <= 'Less than or equal
#define gs >= 'Greater than or equal
#define gt > 'Greater than
#define db data
#define dw db
#define dd dw
#define df dd
#define dl dl
#define ds ds
#define opr operator
' def SYSTEM_BUS_T.pokeb(byval adr as SYSTEM_TYPE, byval v as SYSTEM_TYPE)
#define mov_r0(x) computer.cpu_mos6510->mem->pokeb &H000000001, x ' move r0, [number]
#define mov_r1(x) computer.cpu_mos6510->mem->pokeb &H000000002, x ' move r1, [number]
#define mov_r2(x) computer.cpu_mos6510->mem->pokeb &H000000003, x ' move r2, [number]
#define mov_r0_r1 computer.cpu_mos6510->mem->pokeb &H000000004, 0 ' move r0, r1
#define mov_r0_r2 computer.cpu_mos6510->mem->pokeb &H000000005, 0 ' move r0, r2
#define mov_r1_r0 computer.cpu_mos6510->mem->pokeb &H000000006, 0 ' move r1, r0
#define mov_r1_r2 computer.cpu_mos6510->mem->pokeb &H000000007, 0 ' move r1, r2
#define mov_r2_r0 computer.cpu_mos6510->mem->pokeb &H000000008, 0 ' move r2, r0
#define mov_r2_r1 computer.cpu_mos6510->mem->pokeb &H000000009, 0 ' move r2, r1
#define mov_pc_r0 computer.cpu_mos6510->mem->pokeb &H00000000A, 0 ' move pc, r0
#define mov_pc_r1 computer.cpu_mos6510->mem->pokeb &H00000000B, 0 ' move pc, r1
#define mov_pc_r2 computer.cpu_mos6510->mem->pokeb &H00000000C, 0 ' move pc, r2
#define mov_adr0_r0 computer.cpu_mos6510->mem->pokeb &H00000000D, 0 ' move adr0, r0
#define mov_adr0_r1 computer.cpu_mos6510->mem->pokeb &H00000000E, 0 ' move adr0, r1
#define mov_adr0_r2 computer.cpu_mos6510->mem->pokeb &H00000000F, 0 ' move adr0, r2
#define mov_adr1_r0 computer.cpu_mos6510->mem->pokeb &H000000010, 0 ' move adr1, r0
#define mov_adr1_r1 computer.cpu_mos6510->mem->pokeb &H000000011, 0 ' move adr1, r1
#define mov_adr1_r2 computer.cpu_mos6510->mem->pokeb &H000000012, 0 ' move adr1, r2
#define mov_adr2_r0 computer.cpu_mos6510->mem->pokeb &H000000013, 0 ' move adr2, r0
#define mov_adr2_r1 computer.cpu_mos6510->mem->pokeb &H000000014, 0 ' move adr2, r1
#define mov_adr2_r2 computer.cpu_mos6510->mem->pokeb &H000000015, 0 ' move adr2, r2
#define mov_red1_r0 computer.cpu_mos6510->mem->pokeb &H000000016, 0 ' move red1, r0
#define mov_red2_r0 computer.cpu_mos6510->mem->pokeb &H000000017, 0 ' move red2, r0
#define mov_red3_r0 computer.cpu_mos6510->mem->pokeb &H000000018, 0 ' move red3, r0
#define mov_green1_r0 computer.cpu_mos6510->mem->pokeb &H000000019, 0 ' move green1, r0
#define mov_green2_r0 computer.cpu_mos6510->mem->pokeb &H00000001A, 0 ' move green2, r0
#define mov_green3_r0 computer.cpu_mos6510->mem->pokeb &H00000001B, 0 ' move green3, r0
#define mov_blue1_r0 computer.cpu_mos6510->mem->pokeb &H00000001C, 0 ' move blue1, r0
#define mov_blue2_r0 computer.cpu_mos6510->mem->pokeb &H00000001D, 0 ' move blue2, r0
#define mov_blue3_r0 computer.cpu_mos6510->mem->pokeb &H00000001E, 0 ' move blue3, r0
#define mov_alpha1_r0 computer.cpu_mos6510->mem->pokeb &H00000001F, 0 ' move alpha1, r0
#define mov_alpha2_r0 computer.cpu_mos6510->mem->pokeb &H000000020, 0 ' move alpha2, r0
#define mov_alpha3_r0 computer.cpu_mos6510->mem->pokeb &H000000021, 0 ' move alpha3, r0
#define mov_x0_r0 computer.cpu_mos6510->mem->pokeb &H000000022, 0 ' move x0, r0
#define mov_x1_r0 computer.cpu_mos6510->mem->pokeb &H000000023, 0 ' move x1, r0
#define mov_y0_r0 computer.cpu_mos6510->mem->pokeb &H000000024, 0 ' move y0, r0
#define mov_y1_r0 computer.cpu_mos6510->mem->pokeb &H000000025, 0 ' move y1, r0
#define mov_z0_r0 computer.cpu_mos6510->mem->pokeb &H000000026, 0 ' move z0, r0
#define mov_z1_r0 computer.cpu_mos6510->mem->pokeb &H000000027, 0 ' move z1, r0
#define mov_fg_color_r0 computer.cpu_mos6510->mem->pokeb &H000000028, 0 ' move fg_color, r0
#define mov_bg_color_r0 computer.cpu_mos6510->mem->pokeb &H000000029, 0 ' move bg_color, r0
#define mov_char_h_r0 computer.cpu_mos6510->mem->pokeb &H00000002A, 0 ' move char_h, r0
#define mov_char_w_r0 computer.cpu_mos6510->mem->pokeb &H00000002B, 0 ' move char_w, r0
#define mov_char_ptr,r0 computer.cpu_mos6510->mem->pokeb &H00000002C, 0 ' move char_ptr, r0
#define mov_char_buffer_r0 computer.cpu_mos6510->mem->pokeb &H00000002D, 0 ' move char_buffer, r0
#define mov_bitmask_r0 computer.cpu_mos6510->mem->pokeb &H00000002E, 0 ' move bitmask, r0
#define mov_pixel_size_r0 computer.cpu_mos6510->mem->pokeb &H00000002F, 0 ' move pixel_size, r0
#define mov_radius_r0 computer.cpu_mos6510->mem->pokeb &H000000030, 0 ' move radius, r0
#define mov_string_adr_r0 computer.cpu_mos6510->mem->pokeb &H000000031, 0 ' move string_adr, r0
#define mov_string_len_r0 computer.cpu_mos6510->mem->pokeb &H000000032, 0 ' move string_len, r0
#define mov_r0_x0 computer.cpu_mos6510->mem->pokeb &H000000033, 0 ' move r0, x0
#define mov_x0_r0_2 computer.cpu_mos6510->mem->pokeb &H000000034, 0 ' move x0, r0
#define mov_r0_y0 computer cpu_mos6510->mem->pokeb &H000000035, 0 ' move r0, y0
#define mov_y0_r0_2 computer cpu_mos6510->mem->pokeb &H000000036, 0 ' move y0, r0
#define mov_r0_z0 computer.cpu_mos6510->mem->pokeb &H000000037, 0 ' move r0, z0
#define mov_r0_x1 computer.cpu_mos6510->mem->pokeb &H000000038, 0 ' move r0, x1
#define mov_r0_y1 computer.cpu_mos6510->mem->pokeb &H000000039, 0 ' move r0, y1
#define mov_r0_z1 computer.cpu_mos6510->mem->pokeb &H00000003A, 0 ' move r0, z1
#define mov_z0_r0_2 computer.cpu_mos6510->mem->pokeb &H00000003B, 0 ' move z0, r0
#define mov_r0_z1_2 computer.cpu_mos6510->mem->pokeb &H00000003D, 0 ' move r0, z1
#define mov_r0_a1 computer.cpu_mos6510->mem->pokeb &H00000003E, 0 ' move r0, a1
#define mov_r0_a2 computer.cpu_mos6510->mem->pokeb &H00000003F, 0 ' move r0, a2
#define mov_r0_a3 computer.cpu_mos6510->mem->pokeb $H000000040, 0 ' move r0, a3
#define mov_r0_a4 computer.cpu_mos6510->mem->pokeb &H000000041, 0 ' move r0, a4
#define mov_r0_a5 computer.cpu_mos6510->mem->pokeb &H000000042, 0 ' move r0, a5
#define mov_r0_a6 computer.cpu_mos6510->mem->pokeb &H000000043, 0 ' move r0, a6
#define mov_r0_a7 computer.cpu_mos6510->mem->pokeb &H000000044, 0 ' move r0, a7
#define mov_r0_a8 computer.cpu_mos6510->mem->pokeb &H000000045, 0 ' move r0, a8
#define mov_r0_z1_3 computer.cpu_mos6510->mem->pokeb &H000000046, 0 ' move r0, z0
#define add_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H000000047, 0 ' add r1, r2
#define sub_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H000000048, 0 ' sub r1, r2
#define mul_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H000000049, 0 ' mul r1, r2
#define div_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H00000004A, 0 ' div r1, r2
#define idiv_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H00000004B, 0 ' idiv r1, r2
#define exp_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H00000004C, 0 ' expt r1, r2
#define mod_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H00000004D, 0 ' mod r1, r2
#define neg_r0 computer.cpu_mos6510->mem->pokeb &H00000004E, 0 ' neg r0
#define shl_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H00000004F, 0 ' shl r1, r2
#define shr_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H000000050, 0 ' shr r1, r2
#define eq_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H000000051, 0 ' eq r1, r2
#define ne_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H000000052, 0 ' ne r1, r2
#define lt_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H000000053, 0 ' lt r1, r2
#define lte_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H000000054, 0 ' lte r1, r2
#define gte_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H000000055, 0 ' gte r1, r2
#define gt_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H000000056, 0 ' gt r1, r2
#define and_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H000000057, 0 ' and r1, r2
#define eqv_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H000000058, 0 ' eqv r1, r2
#define imp_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H000000059, 0 ' imp r1, r2
#define or_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H00000005A, 0 ' or r1, r2
#define xor_r0_r1_r2 computer.cpu_mos6510->mem->pokeb &H00000005B, 0 ' xor r1, r2
#define mov_r1_r0_2 computer.cpu_mos6510->mem->pokeb &H00000005C, 0 ' mov r1, r0
#define mov_r2_r0_2 computer.cpu_mos6510->mem->pokeb &H00000005D, 0 ' mov r2, r0
#define inc_r0 computer.cpu_mos6510->mem->pokeb &H00000005E, 0 ' inc r0
#define inc_r1 computer.cpu_mos6510->mem->pokeb &H00000005F, 0 ' inc r1
#define inc_r2 computer.cpu_mos6510->mem->pokeb &H000000060, 0 ' inc r2
#define dec_r0 computer.cpu_mos6510->mem->pokeb &H000000061, 0 ' dec r0
#define dec_r1 computer.cpu_mos6510->mem->pokeb &H000000062, 0 ' dec r1
#define dec_r2 computer.cpu_mos6510->mem->pokeb &H000000063, 0 ' dec r2
'Microcode
'Get P Register
#define get_status_flag computer.cpu_mos6510->p ' get status flag
#define get_carry_flag computer.cpu_mos6510->f.c ' gets cary flag
#define get_sero_flag computer.cpu_mos6510->f.z ' gets zero flag
#define get_interrupt_flag computer.cpu_mos6510->f.i ' gets interrupt flag
#define get_decimal_flag computer.cpu_mos6510->f.d ' gets decimal flag
#define get_borrow_flag computer.cpu_mos6510->f.b ' gets borrow flag
#define get_half_carry_flag computer.cpu_mos6510->f.h ' gets half carry flag
#define get_overflow_flag computer.cpu_mos6510->f.v ' gets overflow flag
#define get_negative_flag computer.cpu_mos6510->f.n ' gets negtive flag
'Set P Register
#define set_status_flag(x) mov(computer.cpu_mos6510->p, x) ' set status flag
#define set_carry_flag(x) mov(computer.cpu_mos6510->f.c, x) ' sets cary flag
#define set_sero_flag(x) mov(computer.cpu_mos6510->f.z, x) ' sets zero flag
#define set_interrupt_flag(x) mov(computer.cpu_mos6510->f.i, x) ' sets interrupt flag
#define set_decimal_flag(x) mov(computer.cpu_mos6510->f.d, x) ' sets decimal flag
#define set_borrow_flag(x) mov(computer.cpu_mos6510->f.b, x) ' sets borrow flag
#define set_half_carry_flag(x) mov(computer.cpu_mos6510->f.h, x) ' sets half carry flag
#define set_overflow_flag(x) mov(computer.cpu_mos6510->f.v, x) ' sets overflow flag
#define set_negative_flag(x) mov(computer.cpu_mos6510->f.n, x) ' sets negtive flag
'Addressing Modes
#define fun_adr_imm computer.cpu_mos6510->adr_imm
#define fun_adr_rel computer.cpu_mos6510->adr_rel
#define fun_adr_zero computer.cpu_mos6510->adr_zero
#define fun_adr_zero_x computer.cpu_mos6510->adr_zerox
#define fun_adr_zero_y computer.cpu_mos6510->adr_zeroy
#define fun_adr_abs computer.cpu_mos6510->adr_abs
#define fun_adr_abs_x computer.cpu_mos6510->adr_absx
#define fun_adr_abs_y computer.cpu_mos6510->adr_absy
#define fun_adr_ind computer.cpu_mos6510->adr_ind
#define fun_adr_ind_x computer.cpu_mos6510->adr_indx
#define fun_adr_ind_y computer.cpu_mos6510->adr_indy
#define fun_adr_unk computer.cpu_mos6510->adr_unk
#define sub_push(x) computer.cpu_mos6510->push(x) ' pushes dat on to the stack
#define fun_pull ' pulls data from off the stack
'Get Registers
#define get_a computer.cpu_mos6510->a ' get accumulator(unsigned)
#define get_x computer.cpu_mos6510->x ' get index register X(unsigned)
#define get_y computer.cpu_mos6510->y ' get index register Y(unsigned)
#define get_pc computer.cpu_mos6510->pc ' get program counter
#define get_pl computer.cpu_mos6510->pl ' get program counter(low byte)
#define get_ph computer.cpu_mos6510->ph ' get program counter(high byte)
#define get_sp computer.cpu_mos6510->sp ' get stack pointer
#define get_s computer.cpu_mos6510->s ' get stack pointer(low byte/LSB)
#define get_msb computer.cpu_mos6510->msb ' get stack pointer(high byte/MSB)
#define get_sa computer.cpu_mos6510->sa ' get accumulator(signed)
#define get_sx computer.cpu_mos6510->sx ' get index register X(signed)
#define get_sy computer.cpu_mos6510->sy ' get index register Y(signed)
'Set Registers
#define set_a(r) mov(computer.cpu_mos6510->a, r) ' set accumulator(unsigned)
#define set_x(r) mov(computer.cpu_mos6510->x, r) ' set index register X(unsigned)
#define set_y(r) mov(computer.cpu_mos6510->y, r) ' set index register Y(unsigned)
#define set_pc(r) mov(computer.cpu_mos6510->pc, r) ' set program counter
#define set_pl(r) mov(computer.cpu_mos6510->pl, r) ' set program counter(low byte)
#define set_ph(r) mov(computer.cpu_mos6510->ph, r) ' set program counter(high byte)
#define set_sp(r) mov(computer.cpu_mos6510->sp, r) ' set stack pointer
#define set_s(r) mov(computer.cpu_mos6510->s, r) ' set stack pointer(low byte/LSB)
#define set_msb(r) mov(computer.cpu_mos6510->msb, r) ' set stack pointer(high byte/MSB)
#define set_sa(r) mov(computer.cpu_mos6510->sa, r) ' set accumulator(signed)
#define set_sx(r) mov(computer.cpu_mos6510->sx, r) ' set index register X(signed)
#define set_sy(r) mov(computer.cpu_mos6510->sy, r) ' set index register Y(signed)
#define fun_readbyte(x) computer.cpu_mos6510->mem->readbyte(x) ' read signed byte from memory
#define fun_readubyte(x) computer.cpu_mos6510->mem->readubyte(x) ' read unsigned byte from memory
#define fun_readushort(x) computer.cpu_mos6510->mem->readushort(x) ' read unsigned short from memory
#define sub_writebyte(x, y) computer.cpu_mom6510->mem->writebyte(x, y) ' write byte to memory
#define sub_writeubyte(x, y) computer.cpu_mos6510->mem->writeubyte(x, y) ' write unsigned byte to memory
#define sub_writeushort(x, y) computer.cpu_mos6510->mem->writeushort(x, y) ' write unsigned short to memory
'mov(computer.cpu_mos6510->A,0)
'Logic Gates
#define logic_xnor(x, y) not(x xor y) 'XNOR
#define logic_xor(x, y) x xor y 'XOR
#define logic_nor(x, y) not(x or y) 'NOR
#define logic_or(x, y) x or y 'OR
#define logic_nand(x, y) not(x and y) 'NAND
#define logic_and(x, y) x and y 'AND
#define logic_not(x) not x 'NOT
'Byte Operations
#define check_bit(x, y) (logic_and((x),(1 shl (y))))
#define low_nibble(x) (logic_and(x,&H0F))
#define high_nibble(x) ((logic_and(x,&HF0)) shr 4)
'ASCII To PETSCII converter
'#define ASCII_TO_PETSCII(adr, a) if logic_and(mem64(adr add a) gt 31,mem64(adr add a) lt 64) then _
' mov(mem64(adr add a),mem64(adr add a) add 32
'Fast PSET
#Define PutPixel(_x, _y, colour) *cptr(ulongint ptr, pScrn + (_y) * pitch + (_x) shl 2) = (colour)
'Fast POINT
#Define GetPixel(_x, _y) *cptr(ulongint ptr, pScrn + (_y) * pitch + (_x) shl 2)