Project Manhattan

User projects written in or related to FreeBASIC.
fatman2021
Posts: 214
Joined: Dec 14, 2013 0:43

Re: Project Manhattan

Post by fatman2021 »

language/compiler selector

Code: Select all

	   case peek(ubyte,@nibbles(&B0011)) ' 003
	    mov(filename,"tmp.bas"):   mov(compiler,"fbc ")                      ' FreeBASIC 
	   case peek(ubyte,@nibbles(&B0100)) ' 004
	   	mov(filename,"tmp.bas"):   mov(compiler,"fbc -lang qb ")             ' QBASIC 1.1
	   case peek(ubyte,@nibbles(&B0101)) ' 005	    
	    mov(filename,"tmp.glsl"):  mov(compiler,"")                          ' OpenGL Shading Language
	   case peek(ubyte,@nibbles(&B0110)) ' 006
	    mov(filename,"tmp.cob"):   mov(compiler,"cobc -x -free ")            ' GNU COBOL
	   case peek(ubyte,@nibbles(&B0111)) ' 007
	    mov(filename,"tmp.f77"):   mov(compiler,"gfortran -std=legacy ")     ' GNU FORTRAN 77
	   case peek(ubyte,@nibbles(&B1000)) ' 008
	    mov(filename,"tmp.pas"):   mov(compiler,"fpc ")                      ' GNU PASCAL
	   case peek(ubyte,@nibbles(&B1001)) ' 009
	    mov(filename,"tmp.osl"):   mov(compiler,"")                          ' Open Shading Language
	   case peek(ubyte,@nibbles(&B1010)) ' 010
	    mov(filename,"tmp.pov"):   mov(compiler,"povray ")                   ' Persistence of Vision Raytracer
	   case peek(ubyte,@nibbles(&B1011)) ' 011
	    mov(filename,"tmp.java"):  mov(compiler,"java ")                     ' Java
	   case peek(ubyte,@nibbles(&B1100)) ' 012
	    mov(filename,"tmp.c"):     mov(compiler,"gcc ")                      ' GNU C
	   case peek(ubyte,@nibbles(&B1101)) ' 013
	    mov(filename,"tmp.cpp"):   mov(compiler,"g++ ")                      ' GNU C++
	   case peek(ubyte,@nibbles(&B1110)) ' 014
	    mov(filename,"tmp.cs"):    mov(compiler,"csc ")                      ' C#
	   case peek(ubyte,@nibbles(&B1111)) ' 015
	    mov(filename,"tmp.js"):    mov(compiler,"node ")                     ' JavaScript
	   case peek(ubyte,@nibbles(&B0001)) shl peek(ubyte,@nibbles(&B0100)) ' 016
	    mov(filename,"tmp.php"):   mov(compiler,"php -f ")                   ' PHP
	   case peek(ubyte,@nibbles(&B0001)) shl peek(ubyte,@nibbles(&B0100)) add peek(ubyte,@nibbles(&B0001)) ' 017
	    mov(filename,"tmp.py"):    mov(compiler,"python ")                   ' Python
	   case peek(ubyte,@nibbles(&B0001)) shl peek(ubyte,@nibbles(&B0100)) add peek(ubyte,@nibbles(&B0010)) ' 018
	    mov(filename,"tmp.swift"): mov(compiler,"swift ")                    ' Swift
	   case peek(ubyte,@nibbles(&B0001)) shl peek(ubyte,@nibbles(&B0100)) add peek(ubyte,@nibbles(&B0011)) ' 019
	    mov(filename,"tmp.m"):     mov(compiler,"octave --persist ")         ' MATLAB/Octave
	   case peek(ubyte,@nibbles(&B0001)) shl peek(ubyte,@nibbles(&B0100)) add peek(ubyte,@nibbles(&B0100)) ' 020
	    mov(filename,"tmp.kt"):    mov(compiler,"kotlinc ")                  ' Kotlin
	   case peek(ubyte,@nibbles(&B0001)) shl peek(ubyte,@nibbles(&B0100)) add peek(ubyte,@nibbles(&B0101)) ' 021
	    mov(filename,"tmp.r"):     mov(compiler,"rscript ")                  ' R
	   case peek(ubyte,@nibbles(&B0001)) shl peek(ubyte,@nibbles(&B0100)) add peek(ubyte,@nibbles(&B0110)) ' 022
	    mov(filename,"tmp.dart"):  mov(compiler,"dart ")                     ' Dart
	   case peek(ubyte,@nibbles(&B0001)) shl peek(ubyte,@nibbles(&B0100)) add peek(ubyte,@nibbles(&B0111)) ' 023
	    mov(filename,"tmp.scala"): mov(compiler,"scalac ")                   ' Scala

	   ' Open file 
	   case peek(ubyte,@nibbles(&B0001)) shl peek(ubyte,@nibbles(&B0100)) add peek(ubyte,@nibbles(&B1000)) ' 024
	    open filename for output as #1

	   ' Close File
	   case peek(ubyte,@nibbles(&B0001)) shl peek(ubyte,@nibbles(&B0100)) add peek(ubyte,@nibbles(&B1001)) ' 025
	    close #1
fatman2021
Posts: 214
Joined: Dec 14, 2013 0:43

Re: Project Manhattan

Post by fatman2021 »

Compile and execute program

Code: Select all

	   ' Compile and execute program 
	   case peek(ubyte,@nibbles(&B0001)) shl peek(ubyte,@nibbles(&B0100)) add peek(ubyte,@nibbles(&B1010)) ' 026
	    line fgimage, (0,0)-(scr_w, scr_h), rgba(0,0,0,255),bf
	    shell compiler add filename
	    shell "./tmp > tmp.txt"
	    open "tmp.txt" for input as #1
	      mov(scr_pos,0): mov(mem64(49362),0)
	      mov(mem64(49363),0):mov(mem64(49364),0)
	      do until eof(1)
	        line input #1, strCode
	        for in range(mov(index,1),len(strCode))
'                      r0	        
	         mov(mem64(49361),asc(mid(strCode,index,1)))
'                     r0		              r0                         r0           r0
	         if mem64(49361) gt 31 and mem64(49361) lt 64 then mov(mem64(49361),mem64(49361) add 32)
'                  scr_ptr                                          r0	         
             pokeb(&H000004000 add (index subt 1) add scr_pos,(mem64(49361) add &H20) and &H3f) 
            next '1024 + x + 40 * (24 - y)
            mov(scr_pos add,90)
           loop  
           mov(scr_pos,5400)
	      mov(mem64(49364),0)  
	    close #1
	    mov(strCode,"press any key to continue.")
	    for in range(mov(index,1),len(strCode))
'                  r0	        
	     mov(mem64(49361),asc(mid(strCode,index,1)))
'                 r0		             r0                          r0           r0
	     if mem64(49361) gt 31 and mem64(49361) lt 64 then mov(mem64(49361),mem64(49361) add 32)
'              scr_ptr                                           r0	         
         pokeb(&H000004000 add (index subt 1) add scr_pos,(mem64(49361) add &H20) and &H3f)
        next	    
	    shell "rm ./tmp; ./" add filename
	    mov(scr_pos,0):mov(strCode,"")
	    put (0,0),fgimage,pset
	    sleep
	    line fgimage, (0,0)-(scr_w, scr_h), rgba(0,0,0,255),bf
	    put (0,0),fgimage,pset	    
fatman2021
Posts: 214
Joined: Dec 14, 2013 0:43

Re: Project Manhattan

Post by fatman2021 »

Assembly Mnemonics

Code: Select all

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
fatman2021
Posts: 214
Joined: Dec 14, 2013 0:43

Re: Project Manhattan

Post by fatman2021 »

Looks like someone has been using code from off of Wikipedia: ;)

Code: Select all

function smoothstep overload (edge0 as float, edge1 as float, x as float) as float
    if x<edge0 then return 0
    if x>edge1 then return 1
    dim as float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0)
    return t * t * (3.0 - 2.0 * t)
end function
From Wikipedia:

Code: Select all

float smoothstep (float edge0, float edge1, float x)
{
   if (x < edge0)
      return 0;

   if (x >= edge1)
      return 1;

   // Scale/bias into [0..1] range
   x = (x - edge0) / (edge1 - edge0);

   return x * x * (3 - 2 * x);
}
https://en.wikipedia.org/wiki/Smoothstep
fatman2021
Posts: 214
Joined: Dec 14, 2013 0:43

Re: Project Manhattan

Post by fatman2021 »

Started porting the FreeBASIC and QB64 runtimes. Updating and documenting the Shadertoy to FreeBASIC runtime. Started porting over parts of the Win32 API.
fatman2021
Posts: 214
Joined: Dec 14, 2013 0:43

Re: Project Manhattan

Post by fatman2021 »

I/O emulation:

Code: Select all

' I/O emulation
def SYSTEM_BUS_T.sub__blink(onoff as integer)
    if (onoff = 1) then
        H3C0_blink_enable = 1
    else
        H3C0_blink_enable = 0
    end if    
end def

proc SYSTEM_BUS_T.func__blink() as integer
    return -H3C0_blink_enable
end proc    


def SYSTEM_BUS_T.sub_out(port as integer, data_out as integer)
    if (new_error) then
        return
    end if    
    unsupported_port_accessed = 0
    port = port and 65535
    data_out = data_out and 255

    if (port = &H3C0) then
        H3C0_blink_enable = data_out and (1 shl 3)
        goto done
    end if

    if (port = &H3C7) then '&H3C7, set palette register read index
        H3C7_palette_register_read_index = data_out
        H3C9_read_next = 0
        goto done
    end if
    
    if (port = &H3C8) then '&H3C8, set palette register write index
        H3C8_palette_register_index = data_out
        H3C9_next = 0
        goto done
    end if
    
    '  alpha          =$C005(49157)
    '  red            =$C002(49154)
    '  green          =$C003(49155)
    '  blue           =$C003(49156)
    '  fg_color       =$C0C9(49353)
    '  bg_color       =$C0CA(49354)    
    if (port = &H3C9) then  ' &H3C9, set palette color
        data_out = data_out and 63
        if (write_page->pal) then    ' avoid NULL pointer
            if (H3C9_next = 0) then ' red
                write_page->pal[H3C8_palette_register_index] = &HFF00FFFF _
            and write_page->pal[H3C8_palette_register_index]
                write_page->pal[H3C8_palette_register_index] += _
                (qbr(cast(double,data_out * 4.063492d - 0.4999999d)) shl 16)
                computer.cpu_mos6510->mem->poke64(49154,data_out)
            end if
            if (H3C9_next = 1) then ' green
                write_page->pal[H3C8_palette_register_index] = &HFF00FFFF _
            and write_page->pal[H3C8_palette_register_index]
                write_page->pal[H3C8_palette_register_index] += _
                (qbr(cast(double,data_out * 4.063492d - 0.4999999d)) shl 8)
                computer.cpu_mos6510->mem->poke64(49155,data_out)
            end if
            if (H3C9_next = 2) then ' blue
                write_page->pal[H3C8_palette_register_index] = &HFF00FFFF _
            and write_page->pal[H3C8_palette_register_index]
                write_page->pal[H3C8_palette_register_index] += _
                (qbr(cast(double,data_out * 4.063492d - 0.4999999d)))
                computer.cpu_mos6510->mem->poke64(49156,data_out)
            end if
        end if
        H3C9_next = H3C9_next + 1
        if (H3C9_next = 3) then
            H3C9_next = 0
            H3C8_palette_register_index = H3C8_palette_register_index + 1
            H3C8_palette_register_index = &HFF and H3C8_palette_register_index
        end if
        goto done
    end if

    unsupported_port_accessed = 1
done:
    return
error_ret:
    error(5)
end def

proc SYSTEM_BUS_T.func_inp(port as integer) as integer
    static as integer value
    unsupported_port_accessed = 0
    if ((port > 65535) or (port < -65536)) then
        error(6)
        return 0  ' Overflow
    end if
    port = port and &HFFFF

    if (port = &H3C9) then       ' read palette
        if (write_page->pal) then ' avoid NULL pointer
            ' convert 0-255 value to 0-63 value
            if (H3C9_read_next = 0) then ' red
                value = qbr_double_to_long(((cast(double,((write_page->pal[H3C7_palette_register_read_index] _
                                                  shr 16) and 255))) / 3.984376 - 0.4999999d))
            end if
            if (H3C9_read_next = 1) then ' green
                value = qbr_double_to_long(((cast(double,((write_page->pal[H3C7_palette_register_read_index] _
                                                  shr 8) and 255))) / 3.984376 - 0.4999999d))
            end if
            if (H3C9_read_next = 2) then ' blue
                value = qbr_double_to_long((cast(double,((write_page->pal[H3C7_palette_register_read_index] _
                                                  and 255))) / 3.984376 - 0.4999999d))
            end if            
            H3C9_read_next = H3C9_read_next + 1
            if (H3C9_read_next = 3) then
                H3C9_read_next = 0
                H3C7_palette_register_read_index = H3C7_palette_register_read_index + 1
                H3C7_palette_register_read_index = &HFF and H3C7_palette_register_read_index
            end if
            return value
        end if         '->pal
        return 0 ' non-palette modes
    end if
    /'
        3dAh (R):  Input Status #1 Register
        bit   0  Either Vertical or Horizontal Retrace active if set
        1  Light Pen has triggered if set
        2  Light Pen switch is open if set
        3  Vertical Retrace in progress if set
        4-5  Shows two of the 6 color outputs, depending on 3C0h index 12h.
        Attr: Bit 4-5:   Out bit 4  Out bit 5
        0          Blue       Red
        1        I Blue       Green
        2        I Red      I Green
    '/

    if (port = &H3DA) then
        value = 0
        if (vertical_retrace_happened or vertical_retrace_in_progress) then
            vertical_retrace_happened = 0
            value = value or 8
        end if
        return value
    end if
'
'    if (port = &H60) then
'        ' return last scancode event
'        if (port60h_events) then
'            value = port60h_event(0)
'            if (port60h_events > 1) then
'                memmove(port60h_event, port60h_event + 1, 255)
'             end if
'            port60h_events = prot60h_events - 1
'            return value
'        else 
'            return port60h_event(0)
'        end if
'    end if
'
    unsupported_port_accessed = 1
    return 0 ' unknown port!
end proc

def SYSTEM_BUS_T.sub_wait(port as integer, andexpression as integer, xorexpression as integer, passed as integer)
    if (new_error) then
        return
    end if
    ' 1. read value from port
    ' 2. value^=xorexpression (if passed!)
    ' 3. value^=andexpression
    ' IMPORTANT: Wait returns immediately if given port is unsupported by QB64 so program
    '           can continue
    static as integer value

    ' error & range checking
    if ((port > 65535) or (port < -65536)) then
        error(6)
        return ' Overflow
    end if
    port = port and &HFFFF
    if ((andexpression < -32768) or (andexpression > 65535)) then
        error(6)
        return ' Overflow
    end if
    andexpression = andexpression and &HFF
    if (passed) then
        if ((xorexpression < -32768) or (xorexpression > 65535)) then
            error(6)
            return ' Overflow
        end if
   end if
    xorexpression = xorexpression and &HFF

wait_loop:
    value = func_inp(port)
    if (passed) then
        value = value xor xorexpression
    end if    
    value = value and andexpression
    if (value or unsupported_port_accessed or stop_program) then
        return
    end if    
    Sleep(1)
    goto wait_loop
end def
coderJeff
Site Admin
Posts: 3942
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Project Manhattan

Post by coderJeff »

What is this exactly? I seen the posts for a few weeks now. Not sure what to make of it. What are users supposed to do with the code snippets posted to the forum?
marcov
Posts: 3360
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Project Manhattan

Post by marcov »

fatman2021 wrote: Jul 02, 2022 2:41 mov(filename,"tmp.pas"): mov(compiler,"fpc ") ' GNU PASCAL
No! :twisted: :twisted: :twisted:

fpc <> gpc.
fatman2021
Posts: 214
Joined: Dec 14, 2013 0:43

Re: Project Manhattan

Post by fatman2021 »

coderJeff wrote: Jul 10, 2022 16:04 What is this exactly? I seen the posts for a few weeks now. Not sure what to make of it. What are users supposed to do with the code snippets posted to the forum?
Let me know if there is a bug in the code and provide a fix if possible...
fatman2021
Posts: 214
Joined: Dec 14, 2013 0:43

Re: Project Manhattan

Post by fatman2021 »

1080p Graphics - DRAW statment

Code: Select all

   case 49642 ' 1080p Graphics - DRAW statment
     select case peek(SYSTEM_TYPE,@v)
       '                                                          fg_color
        case 0: draw fgimage, "c" add str(peek(SYSTEM_TYPE,@mem64(49353))) add "M" _
        _'                                                        r0
                                  add str(peek(SYSTEM_TYPE,@mem64(49361))) add _
                              "," add str(peek(SYSTEM_TYPE,@mem64(49362)))
       '                                                          r1
       
       '                                                          fg_color
        case 1: draw fgimage, "c" add str(peek(SYSTEM_TYPE,@mem64(49353))) _
       _'                                                         r0 
                          add "u" add str(peek(SYSTEM_TYPE,@mem64(49361)))
        
       '                                                         fg_color
        case 2: draw fgimage, "c" add str(peek(SYSTEM_TYPE,@mem64(49353))) _
      _'                                                          r0 
                          add "d" add str(peek(SYSTEM_TYPE,@mem64(48361)))
        
       '                                                          fg_color
        case 3: draw fgimage, "c" add str(peek(SYSTEM_TYPE,@mem64(49353))) _
      _'                                                          r0
                          add "l" add str(peek(SYSTEM_TYPE,@mem64(48361)))
        
       '                                                          fg_color
        case 4: draw fgimage, "c" add str(peek(SYSTEM_TYPE,@mem64(49353))) _
       _'                                                         r0
                          add "r" add str(peek(SYSTEM_TYPE,@mem64(49361)))
        
       '                                                          fg_color
        case 5: draw fgimage, "c" add str(peek(SYSTEM_TYPE,@mem64(49353))) _
      _'                                                          r0  
                          add "e" add str(peek(SYSTEM_TYPE,@mem64(49361)))
      
       '                                                          fg_color 
        case 6: draw fgimage, "c" add str(peek(SYSTEM_TYPE,@mem64(49353))) _
      _'                                                          r0
                          add "f" add str(peek(SYSTEM_TYPE,@mem64(49361)))
        
       '                                                          fg_color
        case 7: draw fgimage, "c" add str(peek(SYSTEM_TYPE,@mem64(49353))) _
      _'                                                          r0  
                          add "g" add str(peek(SYSTEM_TYPE,@mem64(49361)))
        
       '                                                          fg_color  
        case 8: draw fgimage, "c" add str(peek(SYSTEM_TYPE,@mem64(49353))) _
      _'                                                          r0
                          add "h" add str(peek(SYSTEM_TYPE,@mem64(49361)))

       '                                                          fg_color
        case 9: draw fgimage, "c" add str(peek(SYSTEM_TYPE,@mem64(49353)))
       
       '                                                           fg_color 
        case 10: draw fgimage, "c" add str(peek(SYSTEM_TYPE,@mem64(49353))) _
      _'                                                           r0  
                           add "p" add str(peek(SYSTEM_TYPE,@mem64(49361))) add _
      _'                                                           r1
                               "," add str(peek(SYSTEM_TYPE,@mem64(49362)))
        
       '                                                           fg_color 
        case 11: draw fgimage, "c" add str(peek(SYSTEM_TYPE,@mem64(49353))) add _
      _'                                                           r0  
                               "s" add str(peek(SYSTEM_TYPE,@mem64(49361)))
        
       '                                                           fg_color 
        case 12: draw fgimage, "c" add str(peek(SYSTEM_TYPE,@mem64(49353))) add _
      _ '                                                          r0 
                               "a" add str(peek(SYSTEM_TYPE,@mem64(49361)))
       
       '                                                           fg_color
        case 13: draw fgimage, "c" add str(peek(SYSTEM_TYPE,@mem64(49353))) add "ta" _
                                   add str(peek(SYSTEM_TYPE,@mem64(49361)))
       '                                                           r0             
       
       '                                                           fg_color
        case 14: draw fgimage, "c" add str(peek(SYSTEM_TYPE,@mem64(49353))) add strCode: strCode = "" 
        
        case 15: draw fgimage, "b" add strCode: strCode = ""
       
       '                                                           fg_color 
        case 16: draw fgimage, "c" add str(peek(SYSTEM_TYPE,@mem64(49353))) add "n" add strCode: strCode = ""
     end select    
deltarho[1859]
Posts: 3575
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Project Manhattan

Post by deltarho[1859] »

fatman2021 wrote:Let me know if there is a bug in the code and provide a fix if possible...
Perhaps I need another cup of tea. Is that supposed to answer coderJeff's question?
jepalza
Posts: 112
Joined: Feb 24, 2010 10:08
Location: Spain (Bilbao)

Re: Project Manhattan

Post by jepalza »

:lol:
In spanish we have an expresion for this:
"donde vas?, manzanas traigo" (it's looks like "where you go?, apples I bring")

I don't speak English, I don't understand English expressions, but I can see that "something" is wrong with this thread.

I also ask coderjeff's question: what's the point of all this code? I haven't been able to understand anything, neither how it's executed, nor how it's programmed, nor where it's going. :?
fatman2021
Posts: 214
Joined: Dec 14, 2013 0:43

Re: Project Manhattan

Post by fatman2021 »

jepalza wrote: Jul 11, 2022 15:29 :lol:
In spanish we have an expresion for this:
"donde vas?, manzanas traigo" (it's looks like "where you go?, apples I bring")

I don't speak English, I don't understand English expressions, but I can see that "something" is wrong with this thread.

I also ask coderjeff's question: what's the point of all this code? I haven't been able to understand anything, neither how it's executed, nor how it's programmed, nor where it's going. :?
Here are some GLUT prototypes for you:

Code: Select all

   ' Initialization functions, see fglut_init.c
   '/
  declare FGAPI def    FGAPIENTRY glutInit               overload ( pargc as integer ptr, argv as ubyte ptr)
  declare FGAPI def    FGAPIENTRY glutInitWindowPosition overload ( x as integer, y  as integer)
  declare FGAPI def    FGAPIENTRY glutInitWindowSize     overload ( width_data as integer, height_data  as integer)
  declare FGAPI def    FGAPIENTRY glutInitDisplayMode    overload ( displayMode as uinteger)
  declare FGAPI def    FGAPIENTRY glutInitDisplayString  overload ( displayMode as const byte ptr )
I am going to be patching GLUT using Mesa 6.0 for DOS code.
coderJeff
Site Admin
Posts: 3942
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Project Manhattan

Post by coderJeff »

@fatman2021, perhaps you can update your readme.md, or post some instructions to show a first step or first couple of steps; show us how these code posts fit in. Hopefully you have noticed that the feed back so far is trying to figure what it is you are offering or how to assist.
fatman2021
Posts: 214
Joined: Dec 14, 2013 0:43

Re: Project Manhattan

Post by fatman2021 »

coderJeff wrote: Jul 13, 2022 1:11 @fatman2021, perhaps you can update your readme.md, or post some instructions to show a first step or first couple of steps; show us how these code posts fit in. Hopefully you have noticed that the feed back so far is trying to figure what it is you are offering or how to assist.
Like a BSD distribution, everything is developed and compiled as a single unit.

Code: Select all

fbc -fpmode fast -fpu sse -w all  "c64dvd-glsl.bas" -map c64dvd-glsl.map -strip  -Wc -mcmodel=small -Wc -msse2avx -Wc -Ofast -Wc -ffp-contract=fast -Wc -foptimize-sibling-calls -Wc -foptimize-strlen -Wc -fno-inline -Wc -save-temps -Wc -O3 -Wc -msse2avx
README.md
https://github.com/fatman2021/project-m ... /README.md

c64dvd-glsl.bas
https://github.com/fatman2021/project-m ... d-glsl.bas
Post Reply