ilxi.bas 9.05 KB
Newer Older
John P. Willis's avatar
John P. Willis committed
1 2 3 4
'
' ilxi.bas
'

John P. Willis's avatar
John P. Willis committed
5 6 7
#include "ilxi.bi"
#include "cpu.bi"
#include "lexer.bi"
8
#include "storage.bi"
John P. Willis's avatar
John P. Willis committed
9
#include "asm.bi"
10
#include "util.bi"
11
#include "console.bi"
John P. Willis's avatar
John P. Willis committed
12
#include "disk.bi"
John P. Willis's avatar
John P. Willis committed
13
#include "bus.bi"
14
#include "message.bi"
15
#include "help.bi"
John P. Willis's avatar
John P. Willis committed
16

John P. Willis's avatar
John P. Willis committed
17 18 19
startup

sub startup()
20 21 22

    color 12,0: color 7,0       ' hack to get around weird terminal bug around 7 being the default
    cls
23 24 25
    
    message_init
    
26

27
    message_print "ILXI Virtual Machine"
28 29
    message_print " Copyright (C) 2015 Coherent Logic Development LLC"
    message_print ""
John P. Willis's avatar
John P. Willis committed
30

John P. Willis's avatar
John P. Willis committed
31 32
    bus_clear
    console_attach
John P. Willis's avatar
John P. Willis committed
33
    disk_attach
John P. Willis's avatar
John P. Willis committed
34

John P. Willis's avatar
John P. Willis committed
35 36 37 38 39 40 41
    init_cpu    
    cli

    end
end sub

sub cli()
John P. Willis's avatar
John P. Willis committed
42

43
    dim last_cmd as string
John P. Willis's avatar
John P. Willis committed
44 45 46 47 48 49 50 51
    dim cli_cmd as string
    dim cmd_name as string
    dim trace as integer 
    dim arg_count as integer = 0

    trace = 0

    do
52 53 54
        last_cmd = cli_cmd

        mutexlock console_mutex
55
	    line input "ilxi> ", cli_cmd	
56 57
        mutexunlock console_mutex
        
John P. Willis's avatar
John P. Willis committed
58
        if cli_cmd = "" then cli_cmd = last_cmd              
59

John P. Willis's avatar
John P. Willis committed
60 61 62 63
	    arg_count = lex(cli_cmd)
	    cmd_name = get_lexer_entry(0).strval
	
	    select case cmd_name
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
            case "loadpage", "lp"
                dim img_file as string = get_lexer_entry(1).strval
                dim page_index as integer

                
                if get_lexer_entry(2).lexer_class = LC_BYTE then
                    page_index = get_lexer_entry(2).byteval
                else
                    page_index = get_lexer_entry(2).intval
                end if

                st_load_page img_file, page_index
            case "savepage", "sp"
                dim img_file as string = get_lexer_entry(1).strval
                dim page_index as integer

                
                if get_lexer_entry(2).lexer_class = LC_BYTE then
                    page_index = get_lexer_entry(2).byteval
                else
                    page_index = get_lexer_entry(2).intval
                end if

                st_save_page img_file, page_index
John P. Willis's avatar
John P. Willis committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
            case "writesect", "ws"

                dim iobase as ushort = disk_get_iobase()
                dim page_index as integer
                dim page_offset as integer
                dim disk_channel as ushort
                dim disk_track as ushort
                dim disk_sector as ushort
                
                if get_lexer_entry(1).lexer_class = LC_BYTE then
                    page_index = get_lexer_entry(1).byteval
                else
                    page_index = get_lexer_entry(1).intval
                end if

                if get_lexer_entry(2).lexer_class = LC_BYTE then
                    page_offset = get_lexer_entry(2).byteval
                else
                    page_offset = get_lexer_entry(2).intval
                end if

                if get_lexer_entry(3).lexer_class = LC_BYTE then
                    disk_channel = get_lexer_entry(3).byteval
                else
                    disk_channel = get_lexer_entry(3).intval
                end if

                if get_lexer_entry(4).lexer_class = LC_BYTE then
                    disk_track = get_lexer_entry(4).byteval
                else
                    disk_track = get_lexer_entry(4).intval
                end if

                if get_lexer_entry(5).lexer_class = LC_BYTE then
                    disk_sector = get_lexer_entry(5).byteval
                else
                    disk_sector = get_lexer_entry(5).intval
                end if

                disk_output iobase + 0, disk_channel
                disk_output iobase + 1, page_index
                disk_output iobase + 2, page_offset
                disk_output iobase + 3, disk_track

John P. Willis's avatar
John P. Willis committed
132
                disk_output iobase + 5, disk_sector
John P. Willis's avatar
John P. Willis committed
133 134
               

135
            case "assemble", "a"
John P. Willis's avatar
John P. Willis committed
136 137 138 139 140 141 142 143 144 145
                dim le_origin as lexer_entry
                dim origin_addr as ushort

                if get_lexer_entry(1).lexer_class = LC_BYTE then
                    origin_addr = get_lexer_entry(1).byteval
                else
                    origin_addr = get_lexer_entry(1).intval
                end if

                asm_assemble_interactive origin_addr
146
            case "disassemble", "di"
147
                dim page_addr as ushort              
148 149 150 151
                dim start_offset_addr as ushort
                dim da_count as ushort

                page_addr = cpu_state.cp
152 153

                if get_lexer_entry(1).lexer_class = LC_BYTE then
154
                    start_offset_addr = get_lexer_entry(1).byteval
155
                else
156
                    start_offset_addr = get_lexer_entry(1).intval
157 158 159
                end if

                if get_lexer_entry(2).lexer_class = LC_BYTE then
160
                    da_count = get_lexer_entry(2).byteval
161
                else
162 163 164 165
                    da_count = get_lexer_entry(2).intval
                endif

                asm_disassemble_range page_addr, start_offset_addr, da_count
166

167 168 169 170 171 172 173 174
            case "step"            
                if cpu_get_flag(FL_HALT) = 0 then
                    if cpu_get_flag(FL_DEBUG) = 0 then cpu_set_flag FL_DEBUG
                    cpu             	    
                else
                    message_print "cli():  CPU is halted. Type 'reset' at the prompt before attempting 'step'."
                end if

John P. Willis's avatar
John P. Willis committed
175 176 177
	        case "getr"
	            ilxi_getr get_lexer_entry(1).strval
	        case "setr"
178
	       	    dim regval as integer
John P. Willis's avatar
John P. Willis committed
179 180 181 182 183 184 185
	
	            if get_lexer_entry(2).lexer_class = LC_BYTE then
	                regval = get_lexer_entry(2).byteval
	            elseif get_lexer_entry(2).lexer_class = LC_INT then
	                regval = get_lexer_entry(2).intval
	            end if
	
186
	       	    ilxi_setr get_lexer_entry(1).strval, regval
John P. Willis's avatar
John P. Willis committed
187 188 189 190
            case "pushb"
                cpu_push_byte get_lexer_entry(1).byteval
            case "pushw"
                cpu_push_word get_lexer_entry(1).intval
John P. Willis's avatar
John P. Willis committed
191 192 193 194 195 196
	        case "getm"
	            dim le_from as lexer_entry
	            dim le_to as lexer_entry
	
	            dim m_from as integer
	            dim m_to as integer
John P. Willis's avatar
John P. Willis committed
197
		    
John P. Willis's avatar
John P. Willis committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
	            le_from = get_lexer_entry(1)
	            le_to = get_lexer_entry(2)
	
	            if le_from.lexer_class = LC_BYTE then 
	                m_from = le_from.byteval
	            else
	                m_from = le_from.intval
	            end if
	
	
	            if le_to.lexer_class = LC_BYTE then 
	                m_to = le_to.byteval
	            else
	                m_to = le_to.intval
	            end if
213
		   
John P. Willis's avatar
John P. Willis committed
214 215
	            dim i as integer
	            dim k as integer
216 217

                mutexlock console_mutex
John P. Willis's avatar
John P. Willis committed
218 219 220 221 222 223 224 225 226 227 228 229 230
	
	            for i = m_from to m_to step 8
	                print
	                print trim(ilxi_pad_left(hex(cpu_state.dp), "0", 4)); ":"; 
	                print trim(ilxi_pad_left(hex(i), "0", 4)),
	                
	                for k = i to i + 7
	                    print ilxi_pad_left(hex(st_read_byte(cpu_state.dp, k)), "0", 2); " ";
	                next k
	    
	                print " | ";
			
	                for k = i to i + 7
231 232
	                    if st_read_byte(cpu_state.dp, k) <= 31 then color 12,0: print ".";: color 7,0
	                    if st_read_byte(cpu_state.dp, k) > 31 then color 7,0: print chr(st_read_byte(cpu_state.dp, k));
John P. Willis's avatar
John P. Willis committed
233 234 235 236 237
	                next k											   
	            next i
		    
	            print
	            print
238 239 240

                mutexunlock console_mutex

John P. Willis's avatar
John P. Willis committed
241
	        case "setm"
242
	       	    dim le_setm_addr as lexer_entry
John P. Willis's avatar
John P. Willis committed
243 244 245 246 247 248 249 250
	            dim le_setm_value as lexer_entry
	
	            dim setm_addr as integer
	            dim setm_value as integer
	
	    	    le_setm_addr = get_lexer_entry(1)
	            le_setm_value = get_lexer_entry(2)
	
John P. Willis's avatar
John P. Willis committed
251
		    
John P. Willis's avatar
John P. Willis committed
252 253 254 255 256 257 258 259 260
	            if le_setm_addr.lexer_class = LC_BYTE then
	                setm_addr = le_setm_addr.byteval
	            else
	                setm_addr = le_setm_addr.intval
	            end if
	
	            setm_value = le_setm_value.byteval		 
	
	            st_write_byte cpu_state.dp, setm_addr, setm_value
261
	        case "dumpcpu","d"
262
	       	    cpu_dump_state
John P. Willis's avatar
John P. Willis committed
263
	        case "trace"	       	  		    
264 265 266 267
	            if get_lexer_entry(1).byteval = 0 then
                    cpu_clear_flag FL_TRACE
                else
                    cpu_set_flag FL_TRACE
268
                end If
John P. Willis's avatar
John P. Willis committed
269 270 271 272 273
			case "?"
				print help_get_topic("ilxi.xmf", "index")
			case "help"
				print help_get_topic("ilxi.xmf", get_lexer_entry(1).strval)
			case "ver"
John P. Willis's avatar
John P. Willis committed
274
	       	    print "ILXI 0.1"
John P. Willis's avatar
John P. Willis committed
275
	        case "run"
276 277 278 279 280 281
                if cpu_get_flag(FL_HALT) = 0 then
                    cpu_clear_flag FL_DEBUG
               	    cpu
                else
                    message_print "cli():  CPU is halted. Type 'reset' at the prompt before attempting 'run'."
                end if
John P. Willis's avatar
John P. Willis committed
282 283
	        case "clear", "cls"
				cls
John P. Willis's avatar
John P. Willis committed
284
	        case "reset"
285
	            init_cpu	            
286
            case "exit", "quit"
287
                end
John P. Willis's avatar
John P. Willis committed
288
	        case else
289
	       	    message_print "cli():  invalid command '" & cmd_name & "'"
John P. Willis's avatar
John P. Willis committed
290 291
	    end select
	
John P. Willis's avatar
John P. Willis committed
292
    loop until cli_cmd = "exit"
293 294
end sub

295
sub ilxi_getr(register as string)   
296
    message_print ucase(register) & ": " & trim(hex(cpu_get_reg_alpha(lcase(register))))
297 298 299 300 301 302
end sub

sub ilxi_setr(register as string, value as integer)
    cpu_set_reg_alpha lcase(register), value
end sub