Revision 46
Added by markw over 11 years ago
firmware/hexdump.c | ||
---|---|---|
#include "hexdump.h"
|
||
#include "printf.h"
|
||
|
||
void hexdump_pure(void const * str, int length)
|
||
{
|
||
for (;length>0;--length)
|
||
{
|
||
unsigned char val= *(unsigned char *)str++;
|
||
printf("%02x",val);
|
||
}
|
||
}
|
firmware/joystick.h | ||
---|---|---|
#pragma once
|
||
|
||
struct joystick_status
|
||
{
|
||
char x_;
|
||
char y_;
|
||
char fire_;
|
||
};
|
||
|
||
enum JoyWait {WAIT_QUIET, WAIT_FIRE, WAIT_MOVE, WAIT_EITHER};
|
||
|
||
void joystick_poll(struct joystick_status * status);
|
||
void joystick_wait(struct joystick_status * status, enum JoyWait waitFor);
|
||
|
firmware/mif_file_stuff/rom_prologue.vhd | ||
---|---|---|
DEPTH = 4096; % Memory depth and width are required %
|
||
% DEPTH is the number of addresses %
|
||
WIDTH = 32; % WIDTH is the number of bits of data per word %
|
||
% DEPTH and WIDTH should be entered as decimal numbers %
|
||
ADDRESS_RADIX = HEX; % Address and value radixes are required %
|
||
DATA_RADIX = HEX; % Enter BIN, DEC, HEX, OCT, or UNS; unless %
|
||
% otherwise specified, radixes = HEX %
|
||
-- Specify values for addresses, which can be single address or range
|
||
CONTENT
|
||
BEGIN
|
firmware/mycrt0.s | ||
---|---|---|
/* Startup code for ZPU
|
||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||
|
||
This file is free software; you can redistribute it and/or modify it
|
||
under the terms of the GNU General Public License as published by the
|
||
Free Software Foundation; either version 2, or (at your option) any
|
||
later version.
|
||
|
||
In addition to the permissions in the GNU General Public License, the
|
||
Free Software Foundation gives you unlimited permission to link the
|
||
compiled version of this file with other programs, and to distribute
|
||
those programs without any restriction coming from the use of this
|
||
file. (The General Public License restrictions do apply in other
|
||
respects; for example, they cover modification of the file, and
|
||
distribution when not linked into another program.)
|
||
|
||
This file is distributed in the hope that it will be useful, but
|
||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
General Public License for more details.
|
||
|
||
You should have received a copy of the GNU General Public License
|
||
along with this program; see the file COPYING. If not, write to
|
||
the Free Software Foundation, 59 Temple Place - Suite 330,
|
||
Boston, MA 02111-1307, USA. */
|
||
.file "mincrt0.S"
|
||
|
||
|
||
/* Minimal startup code, usable where the core is complete enough not to require emulated instructions */
|
||
|
||
|
||
.section ".fixed_vectors","ax"
|
||
; KLUDGE!!! we remove the executable bit to avoid relaxation
|
||
.section ".fixed_vectors","a"
|
||
|
||
.macro fixedim value
|
||
im \value
|
||
.endm
|
||
|
||
.macro jmp address
|
||
fixedim \address
|
||
poppc
|
||
.endm
|
||
|
||
.macro fast_neg
|
||
not
|
||
im 1
|
||
add
|
||
.endm
|
||
|
||
.macro mult1bit
|
||
; create mask of lowest bit in A
|
||
loadsp 8 ; A
|
||
im 1
|
||
and
|
||
im -1
|
||
add
|
||
not
|
||
loadsp 8 ; B
|
||
and
|
||
add ; accumulate in C
|
||
|
||
; shift B left 1 bit
|
||
loadsp 4 ; B
|
||
addsp 0
|
||
storesp 8 ; B
|
||
|
||
; shift A right 1 bit
|
||
loadsp 8 ; A
|
||
flip
|
||
addsp 0
|
||
flip
|
||
storesp 12 ; A
|
||
.endm
|
||
|
||
.macro cimpl funcname
|
||
; save R0
|
||
im _memreg
|
||
load
|
||
|
||
; save R1
|
||
im _memreg+4
|
||
load
|
||
|
||
; save R2
|
||
im _memreg+8
|
||
load
|
||
|
||
loadsp 20
|
||
loadsp 20
|
||
|
||
fixedim \funcname
|
||
call
|
||
|
||
; destroy arguments on stack
|
||
storesp 0
|
||
storesp 0
|
||
|
||
im _memreg
|
||
load
|
||
|
||
; poke the result into the right slot
|
||
storesp 24
|
||
|
||
; restore R2
|
||
im _memreg+8
|
||
store
|
||
|
||
; restore R1
|
||
im _memreg+4
|
||
store
|
||
|
||
; restore r0
|
||
im _memreg
|
||
store
|
||
|
||
|
||
storesp 4
|
||
poppc
|
||
.endm
|
||
|
||
|
||
.globl _start
|
||
_start:
|
||
jmp _premain
|
||
|
||
/* vectors */
|
||
/* instruction emulation code */
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
nop
|
||
|
||
# opcode 34
|
||
# offset 0x0000 0040
|
||
.balign 32,0
|
||
_loadh:
|
||
loadsp 4
|
||
; by not masking out bit 0, we cause a memory access error
|
||
; on unaligned access
|
||
im ~0x2
|
||
and
|
||
load
|
||
|
||
; mult 8
|
||
loadsp 8
|
||
im 3
|
||
and
|
||
fast_neg
|
||
im 2
|
||
add
|
||
im 3
|
||
ashiftleft
|
||
; shift right addr&3 * 8
|
||
lshiftright
|
||
im 0xffff
|
||
and
|
||
storesp 8
|
||
|
||
poppc
|
||
|
||
# opcode 35
|
||
# offset 0x0000 0060
|
||
.balign 32,0
|
||
_storeh:
|
||
loadsp 4
|
||
; by not masking out bit 0, we cause a memory access error
|
||
; on unaligned access
|
||
im ~0x2
|
||
and
|
||
load
|
||
|
||
; mask
|
||
im 0xffff
|
||
loadsp 12
|
||
im 3
|
||
and
|
||
fast_neg
|
||
im 2
|
||
add
|
||
im 3
|
||
ashiftleft
|
||
ashiftleft
|
||
not
|
||
|
||
and
|
||
|
||
loadsp 12
|
||
im 0xffff
|
||
|
||
nop
|
||
|
||
fixedim _storehtail
|
||
poppc
|
||
|
||
|
||
# opcode 36
|
||
# offset 0x0000 0080
|
||
.balign 32,0
|
||
_lessthan:
|
||
loadsp 8
|
||
fast_neg
|
||
loadsp 8
|
||
add
|
||
|
||
; DANGER!!!!
|
||
; 0x80000000 will overflow when negated, so we need to mask
|
||
; the result above with the compare positive to negative
|
||
; number case
|
||
loadsp 12
|
||
loadsp 12
|
||
not
|
||
and
|
||
not
|
||
and
|
||
|
||
|
||
; handle case where we are comparing a negative number
|
||
; and positve number. This can underflow. E.g. consider 0x8000000 < 0x1000
|
||
loadsp 12
|
||
not
|
||
loadsp 12
|
||
and
|
||
|
||
or
|
||
|
||
|
||
|
||
flip
|
||
im 1
|
||
and
|
||
|
||
|
||
storesp 12
|
||
storesp 4
|
||
poppc
|
||
|
||
|
||
# opcode 37
|
||
# offset 0x0000 00a0
|
||
.balign 32,0
|
||
_lessthanorequal:
|
||
loadsp 8
|
||
loadsp 8
|
||
lessthan
|
||
loadsp 12
|
||
loadsp 12
|
||
eq
|
||
or
|
||
|
||
storesp 12
|
||
storesp 4
|
||
poppc
|
||
|
||
|
||
# opcode 38
|
||
# offset 0x0000 00c0
|
||
.balign 32,0
|
||
_ulessthan:
|
||
; fish up arguments
|
||
loadsp 4
|
||
loadsp 12
|
||
|
||
/* low: -1 if low bit dif is negative 0 otherwise: neg (not x&1 and (y&1))
|
||
x&1 y&1 neg (not x&1 and (y&1))
|
||
1 1 0
|
||
1 0 0
|
||
0 1 -1
|
||
0 0 0
|
||
|
||
*/
|
||
loadsp 4
|
||
not
|
||
loadsp 4
|
||
and
|
||
im 1
|
||
and
|
||
neg
|
||
|
||
|
||
/* high: upper 31-bit diff is only wrong when diff is 0 and low=-1
|
||
high=x>>1 - y>>1 + low
|
||
|
||
extremes
|
||
|
||
0000 - 1111:
|
||
low= neg(not 0 and 1) = 1111 (-1)
|
||
high=000+ neg(111) +low = 000 + 1001 + low = 1000
|
||
OK
|
||
|
||
1111 - 0000
|
||
low=neg(not 1 and 0) = 0
|
||
high=111+neg(000) + low = 0111
|
||
OK
|
||
|
||
|
||
*/
|
||
loadsp 8
|
||
|
||
flip
|
||
addsp 0
|
||
flip
|
||
|
||
loadsp 8
|
||
|
||
flip
|
||
addsp 0
|
||
flip
|
||
|
||
sub
|
||
|
||
; if they are equal, then the last bit decides...
|
||
add
|
||
|
||
/* test if negative: result = flip(diff) & 1 */
|
||
flip
|
||
im 1
|
||
and
|
||
|
||
; destroy a&b which are on stack
|
||
storesp 4
|
||
storesp 4
|
||
|
||
storesp 12
|
||
storesp 4
|
||
poppc
|
||
|
||
# opcode 39
|
||
# offset 0x0000 00e0
|
||
.balign 32,0
|
||
_ulessthanorequal:
|
||
loadsp 8
|
||
loadsp 8
|
||
ulessthan
|
||
loadsp 12
|
||
loadsp 12
|
||
eq
|
||
or
|
||
|
||
storesp 12
|
||
storesp 4
|
||
poppc
|
||
|
||
|
||
# opcode 40
|
||
# offset 0x0000 0100
|
||
.balign 32,0
|
||
.globl _swap
|
||
_swap:
|
||
breakpoint ; tbd
|
||
|
||
# opcode 41
|
||
# offset 0x0000 0120
|
||
.balign 32,0
|
||
_slowmult:
|
||
im _slowmultImpl
|
||
poppc
|
||
|
||
# opcode 42
|
||
# offset 0x0000 0140
|
||
.balign 32,0
|
||
_lshiftright:
|
||
loadsp 8
|
||
flip
|
||
|
||
loadsp 8
|
||
ashiftleft
|
||
flip
|
||
|
||
storesp 12
|
||
storesp 4
|
||
|
||
poppc
|
||
|
||
|
||
# opcode 43
|
||
# offset 0x0000 0160
|
||
.balign 32,0
|
||
_ashiftleft:
|
||
loadsp 8
|
||
|
||
loadsp 8
|
||
im 0x1f
|
||
and
|
||
fast_neg
|
||
im _ashiftleftEnd
|
||
add
|
||
poppc
|
||
|
||
|
||
|
||
# opcode 44
|
||
# offset 0x0000 0180
|
||
.balign 32,0
|
||
_ashiftright:
|
||
loadsp 8
|
||
loadsp 8
|
||
lshiftright
|
||
|
||
; handle signed value
|
||
im -1
|
||
loadsp 12
|
||
im 0x1f
|
||
and
|
||
lshiftright
|
||
not ; now we have an integer on the stack with the signed
|
||
; bits in the right position
|
||
|
||
; mask these bits with the signed bit.
|
||
loadsp 16
|
||
not
|
||
flip
|
||
im 1
|
||
and
|
||
im -1
|
||
add
|
||
|
||
and
|
||
|
||
; stuff in the signed bits...
|
||
or
|
||
|
||
; store result into correct stack slot
|
||
storesp 12
|
||
|
||
; move up return value
|
||
storesp 4
|
||
poppc
|
||
|
||
# opcode 45
|
||
# offset 0x0000 01a0
|
||
.balign 32,0
|
||
_call:
|
||
; fn
|
||
loadsp 4
|
||
|
||
; return address
|
||
loadsp 4
|
||
|
||
; store return address
|
||
storesp 12
|
||
|
||
; fn to call
|
||
storesp 4
|
||
|
||
pushsp ; flush internal stack
|
||
popsp
|
||
|
||
poppc
|
||
|
||
_storehtail:
|
||
|
||
and
|
||
loadsp 12
|
||
im 3
|
||
and
|
||
fast_neg
|
||
im 2
|
||
add
|
||
im 3
|
||
ashiftleft
|
||
nop
|
||
ashiftleft
|
||
|
||
or
|
||
|
||
loadsp 8
|
||
im ~0x3
|
||
and
|
||
|
||
store
|
||
|
||
storesp 4
|
||
storesp 4
|
||
poppc
|
||
|
||
|
||
# opcode 46
|
||
# offset 0x0000 01c0
|
||
.balign 32,0
|
||
_eq:
|
||
loadsp 8
|
||
fast_neg
|
||
loadsp 8
|
||
add
|
||
|
||
not
|
||
loadsp 0
|
||
im 1
|
||
add
|
||
not
|
||
and
|
||
flip
|
||
im 1
|
||
and
|
||
|
||
storesp 12
|
||
storesp 4
|
||
poppc
|
||
|
||
# opcode 47
|
||
# offset 0x0000 01e0
|
||
.balign 32,0
|
||
_neq:
|
||
loadsp 8
|
||
fast_neg
|
||
loadsp 8
|
||
add
|
||
|
||
not
|
||
loadsp 0
|
||
im 1
|
||
add
|
||
not
|
||
and
|
||
flip
|
||
|
||
not
|
||
|
||
im 1
|
||
and
|
||
|
||
storesp 12
|
||
storesp 4
|
||
poppc
|
||
|
||
|
||
# opcode 48
|
||
# offset 0x0000 0200
|
||
.balign 32,0
|
||
_neg:
|
||
loadsp 4
|
||
not
|
||
im 1
|
||
add
|
||
storesp 8
|
||
|
||
poppc
|
||
|
||
|
||
# opcode 49
|
||
# offset 0x0000 0220
|
||
.balign 32,0
|
||
_sub:
|
||
loadsp 8
|
||
loadsp 8
|
||
fast_neg
|
||
add
|
||
storesp 12
|
||
|
||
storesp 4
|
||
|
||
poppc
|
||
|
||
|
||
# opcode 50
|
||
# offset 0x0000 0240
|
||
.balign 32,0
|
||
_xor:
|
||
loadsp 8
|
||
not
|
||
loadsp 8
|
||
and
|
||
|
||
loadsp 12
|
||
loadsp 12
|
||
not
|
||
and
|
||
|
||
or
|
||
|
||
storesp 12
|
||
storesp 4
|
||
poppc
|
||
|
||
# opcode 51
|
||
# offset 0x0000 0260
|
||
.balign 32,0
|
||
_loadb:
|
||
loadsp 4
|
||
im ~0x3
|
||
and
|
||
load
|
||
|
||
loadsp 8
|
||
im 3
|
||
and
|
||
fast_neg
|
||
im 3
|
||
add
|
||
; x8
|
||
addsp 0
|
||
addsp 0
|
||
addsp 0
|
||
|
||
lshiftright
|
||
|
||
im 0xff
|
||
and
|
||
storesp 8
|
||
|
||
poppc
|
||
|
||
|
||
# opcode 52
|
||
# offset 0x0000 0280
|
||
.balign 32,0
|
||
_storeb:
|
||
loadsp 4
|
||
im ~0x3
|
||
and
|
||
load
|
||
|
||
; mask away destination
|
||
im _mask
|
||
loadsp 12
|
||
im 3
|
||
and
|
||
addsp 0
|
||
addsp 0
|
||
add
|
||
load
|
||
|
||
and
|
||
|
||
|
||
im _storebtail
|
||
poppc
|
||
|
||
# opcode 53
|
||
# offset 0x0000 02a0
|
||
.balign 32,0
|
||
_div:
|
||
jmp ___div
|
||
|
||
# opcode 54
|
||
# offset 0x0000 02c0
|
||
.balign 32,0
|
||
_mod:
|
||
jmp ___mod
|
||
|
||
# opcode 55
|
||
# offset 0x0000 02e0
|
||
.balign 32,0
|
||
.globl _eqbranch
|
||
_eqbranch:
|
||
loadsp 8
|
||
|
||
; eq
|
||
|
||
not
|
||
loadsp 0
|
||
im 1
|
||
add
|
||
not
|
||
and
|
||
flip
|
||
im 1
|
||
and
|
||
|
||
; mask
|
||
im -1
|
||
add
|
||
loadsp 0
|
||
storesp 16
|
||
|
||
; no branch address
|
||
loadsp 4
|
||
|
||
and
|
||
|
||
; fetch boolean & neg mask
|
||
loadsp 12
|
||
not
|
||
|
||
; calc address & mask for branch
|
||
loadsp 8
|
||
loadsp 16
|
||
add
|
||
; subtract 1 to find PC of branch instruction
|
||
im -1
|
||
add
|
||
|
||
and
|
||
|
||
or
|
||
|
||
storesp 4
|
||
storesp 4
|
||
storesp 4
|
||
poppc
|
||
|
||
|
||
# opcode 56
|
||
# offset 0x0000 0300
|
||
.balign 32,0
|
||
.globl _neqbranch
|
||
_neqbranch:
|
||
loadsp 8
|
||
|
||
; neq
|
||
|
||
not
|
||
loadsp 0
|
||
im 1
|
||
add
|
||
not
|
||
and
|
||
flip
|
||
|
||
not
|
||
|
||
im 1
|
||
and
|
||
|
||
; mask
|
||
im -1
|
||
add
|
||
loadsp 0
|
||
storesp 16
|
||
|
||
; no branch address
|
||
loadsp 4
|
||
|
||
and
|
||
|
||
; fetch boolean & neg mask
|
||
loadsp 12
|
||
not
|
||
|
||
; calc address & mask for branch
|
||
loadsp 8
|
||
loadsp 16
|
||
add
|
||
; find address of branch instruction
|
||
im -1
|
||
add
|
||
|
||
and
|
||
|
||
or
|
||
|
||
storesp 4
|
||
storesp 4
|
||
storesp 4
|
||
poppc
|
||
|
||
# opcode 57
|
||
# offset 0x0000 0320
|
||
.balign 32,0
|
||
.globl _poppcrel
|
||
_poppcrel:
|
||
add
|
||
; address of poppcrel
|
||
im -1
|
||
add
|
||
poppc
|
||
|
||
# opcode 58
|
||
# offset 0x0000 0340
|
||
.balign 32,0
|
||
.globl _config
|
||
_config:
|
||
im 1
|
||
nop
|
||
im _hardware
|
||
store
|
||
storesp 4
|
||
poppc
|
||
|
||
# opcode 59
|
||
# offset 0x0000 0360
|
||
.balign 32,0
|
||
_pushpc:
|
||
loadsp 4
|
||
im 1
|
||
add
|
||
storesp 8
|
||
poppc
|
||
|
||
# opcode 60
|
||
# offset 0x0000 0380
|
||
.balign 32,0
|
||
_syscall_emulate:
|
||
.byte 0
|
||
|
||
# opcode 61
|
||
# offset 0x0000 03a0
|
||
.balign 32,0
|
||
_pushspadd:
|
||
pushsp
|
||
im 4
|
||
add
|
||
loadsp 8
|
||
addsp 0
|
||
addsp 0
|
||
add
|
||
storesp 8
|
||
|
||
poppc
|
||
|
||
# opcode 62
|
||
# offset 0x0000 03c0
|
||
.balign 32,0
|
||
_halfmult:
|
||
breakpoint
|
||
|
||
# opcode 63
|
||
# offset 0x0000 03e0
|
||
.balign 32,0
|
||
_callpcrel:
|
||
loadsp 4
|
||
loadsp 4
|
||
add
|
||
im -1
|
||
add
|
||
loadsp 4
|
||
|
||
storesp 12 ; return address
|
||
storesp 4
|
||
pushsp ; this will flush the internal stack.
|
||
popsp
|
||
poppc
|
||
|
||
.text
|
||
|
||
|
||
|
||
|
||
_ashiftleftBegin:
|
||
.rept 0x1f
|
||
addsp 0
|
||
.endr
|
||
_ashiftleftEnd:
|
||
storesp 12
|
||
storesp 4
|
||
poppc
|
||
|
||
_storebtail:
|
||
loadsp 12
|
||
im 0xff
|
||
and
|
||
loadsp 12
|
||
im 3
|
||
and
|
||
|
||
fast_neg
|
||
im 3
|
||
add
|
||
; x8
|
||
addsp 0
|
||
addsp 0
|
||
addsp 0
|
||
|
||
ashiftleft
|
||
|
||
or
|
||
|
||
loadsp 8
|
||
im ~0x3
|
||
and
|
||
|
||
store
|
||
|
||
storesp 4
|
||
storesp 4
|
||
poppc
|
||
|
||
|
||
|
||
|
||
; NB! this is not an EMULATE instruction. It is a varargs fn.
|
||
.globl _syscall
|
||
_syscall:
|
||
syscall
|
||
poppc
|
||
|
||
_slowmultImpl:
|
||
|
||
loadsp 8 ; A
|
||
loadsp 8 ; B
|
||
im 0 ; C
|
||
|
||
.LmoreMult:
|
||
mult1bit
|
||
|
||
; cutoff
|
||
loadsp 8
|
||
.byte (.LmoreMult-.Lbranch)&0x7f+0x80
|
||
.Lbranch:
|
||
neqbranch
|
||
|
||
storesp 4
|
||
storesp 4
|
||
storesp 12
|
||
storesp 4
|
||
poppc
|
||
|
||
___mod:
|
||
cimpl __modsi3
|
||
___div:
|
||
cimpl __divsi3
|
||
|
||
.section ".rodata"
|
||
.balign 4,0
|
||
_mask:
|
||
.long 0x00ffffff
|
||
.long 0xff00ffff
|
||
.long 0xffff00ff
|
||
.long 0xffffff00
|
||
|
||
.section ".text","ax"
|
||
.global _boot
|
||
.balign 4,0
|
||
_boot:
|
||
im 0
|
||
poppc
|
||
|
||
.global _break;
|
||
_break:
|
||
im _break
|
||
poppc ; infinite loop
|
||
|
||
_premain:
|
||
im _break
|
||
nop
|
||
fixedim main
|
||
poppc
|
||
|
||
|
||
.data
|
||
.balign 4,0
|
||
|
||
.globl _hardware
|
||
_hardware:
|
||
.long 0
|
||
.globl _cpu_config
|
||
_cpu_config:
|
||
.long 0
|
||
|
||
|
||
.section ".bss"
|
||
.balign 4,0
|
||
.globl _memreg
|
||
_memreg:
|
||
.long 0
|
||
.long 0
|
||
.long 0
|
||
.long 0
|
||
|
firmware/native/uart.c | ||
---|---|---|
#include "uart.h"
|
||
|
||
#include <stdio.h>
|
||
|
||
char native_command;
|
||
|
||
char receive_buffer[1024*1024];
|
||
int receive_buffer_pos=0;
|
||
int receive_buffer_last=0;
|
||
|
||
void USART_Init( u08 value )
|
||
{
|
||
fprintf(stderr, "USART_Init:%d\n",value);
|
||
}
|
||
|
||
void USART_Transmit_Byte( unsigned char data )
|
||
{
|
||
fprintf(stderr, "USART_Transmit:%02x\n", data);
|
||
}
|
||
|
||
unsigned char USART_Receive_Byte( void )
|
||
{
|
||
unsigned char res = receive_buffer[receive_buffer_pos++];
|
||
fprintf(stderr, "USART_Receive:%02x\n",res);
|
||
return res;
|
||
}
|
||
|
||
int USART_Data_Ready()
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
void USART_Transmit_Mode()
|
||
{
|
||
fprintf(stderr,"USART_Transmit mode\n");
|
||
}
|
||
|
||
void USART_Receive_Mode()
|
||
{
|
||
fprintf(stderr,"USART_Receive mode\n");
|
||
}
|
||
|
||
int USART_Framing_Error()
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
void USART_Wait_Transmit_Complete()
|
||
{
|
||
return;
|
||
}
|
||
|
||
int USART_Command_Line()
|
||
{
|
||
return native_command;
|
||
}
|
||
|
firmware/fat/diskio.h | ||
---|---|---|
/*-----------------------------------------------------------------------
|
||
/ PFF - Low level disk interface modlue include file (C)ChaN, 2009
|
||
/-----------------------------------------------------------------------*/
|
||
|
||
#ifndef _DISKIO
|
||
|
||
#include "integer.h"
|
||
|
||
|
||
/* Status of Disk Functions */
|
||
typedef BYTE DSTATUS;
|
||
|
||
|
||
/* Results of Disk Functions */
|
||
typedef enum {
|
||
RES_OK = 0, /* 0: Function succeeded */
|
||
RES_ERROR, /* 1: Disk error */
|
||
RES_NOTRDY, /* 2: Not ready */
|
||
RES_PARERR /* 3: Invalid parameter */
|
||
} DRESULT;
|
||
|
||
|
||
/*---------------------------------------*/
|
||
/* Prototypes for disk control functions */
|
||
|
||
DSTATUS disk_initialize (void);
|
||
DRESULT disk_readp (BYTE*, DWORD, WORD, WORD);
|
||
DRESULT disk_writep (const BYTE*, DWORD);
|
||
|
||
#define STA_NOINIT 0x01 /* Drive not initialized */
|
||
#define STA_NODISK 0x02 /* No medium in the drive */
|
||
|
||
/* Card type flags (CardType) */
|
||
#define CT_MMC 0x01 /* MMC ver 3 */
|
||
#define CT_SD1 0x02 /* SD ver 1 */
|
||
#define CT_SD2 0x04 /* SD ver 2 */
|
||
#define CT_SDC (CT_SD1|CT_SD2) /* SD */
|
||
#define CT_BLOCK 0x08 /* Block addressing */
|
||
|
||
#define _DISKIO
|
||
#endif
|
firmware/fat/pff.h | ||
---|---|---|
/*---------------------------------------------------------------------------/
|
||
/ Petit FatFs - FAT file system module include file R0.02a (C)ChaN, 2010
|
||
/----------------------------------------------------------------------------/
|
||
/ Petit FatFs module is an open source software to implement FAT file system to
|
||
/ small embedded systems. This is a free software and is opened for education,
|
||
/ research and commercial developments under license policy of following trems.
|
||
/
|
||
/ Copyright (C) 2010, ChaN, all right reserved.
|
||
/
|
||
/ * The Petit FatFs module is a free software and there is NO WARRANTY.
|
||
/ * No restriction on use. You can use, modify and redistribute it for
|
||
/ personal, non-profit or commercial use UNDER YOUR RESPONSIBILITY.
|
||
/ * Redistributions of source code must retain the above copyright notice.
|
||
/
|
||
/----------------------------------------------------------------------------*/
|
||
|
||
#include "integer.h"
|
||
|
||
/*---------------------------------------------------------------------------/
|
||
/ Petit FatFs Configuration Options
|
||
/
|
||
/ CAUTION! Do not forget to make clean the project after any changes to
|
||
/ the configuration options.
|
||
/
|
||
/----------------------------------------------------------------------------*/
|
||
#ifndef _FATFS
|
||
#define _FATFS
|
||
|
||
#define _USE_READ 1 /* 1:Enable pf_read() */
|
||
|
||
#define _USE_DIR 1 /* 1:Enable pf_opendir() and pf_readdir() */
|
||
|
||
#define _USE_LSEEK 1 /* 1:Enable pf_lseek() */
|
||
|
||
#define _USE_WRITE 1 /* 1:Enable pf_write() */
|
||
|
||
#define _FS_FAT12 1 /* 1:Enable FAT12 support */
|
||
#define _FS_FAT32 1 /* 1:Enable FAT32 support */
|
||
|
||
|
||
#define _CODE_PAGE 1
|
||
/* Defines which code page is used for path name. Supported code pages are:
|
||
/ 932, 936, 949, 950, 437, 720, 737, 775, 850, 852, 855, 857, 858, 862, 866,
|
||
/ 874, 1250, 1251, 1252, 1253, 1254, 1255, 1257, 1258 and 1 (ASCII only).
|
||
/ SBCS code pages except for 1 requiers a case conversion table. This
|
||
/ might occupy 128 bytes on the RAM on some platforms, e.g. avr-gcc. */
|
||
|
||
|
||
#define _WORD_ACCESS 0
|
||
/* The _WORD_ACCESS option defines which access method is used to the word
|
||
/ data in the FAT structure.
|
||
/
|
||
/ 0: Byte-by-byte access. Always compatible with all platforms.
|
||
/ 1: Word access. Do not choose this unless following condition is met.
|
||
/
|
||
/ When the byte order on the memory is big-endian or address miss-aligned
|
||
/ word access results incorrect behavior, the _WORD_ACCESS must be set to 0.
|
||
/ If it is not the case, the value can also be set to 1 to improve the
|
||
/ performance and code efficiency. */
|
||
|
||
|
||
/* End of configuration options. Do not change followings without care. */
|
||
/*--------------------------------------------------------------------------*/
|
||
|
||
|
||
|
||
#if _FS_FAT32
|
||
#define CLUST DWORD
|
||
#else
|
||
#define CLUST WORD
|
||
#endif
|
||
|
||
|
||
/* File system object structure */
|
||
|
||
typedef struct {
|
||
BYTE fs_type; /* FAT sub type */
|
||
BYTE flag; /* File status flags */
|
||
BYTE csize; /* Number of sectors per cluster */
|
||
BYTE pad1;
|
||
WORD n_rootdir; /* Number of root directory entries (0 on FAT32) */
|
||
CLUST n_fatent; /* Number of FAT entries (= number of clusters + 2) */
|
||
DWORD fatbase; /* FAT start sector */
|
||
DWORD dirbase; /* Root directory start sector (Cluster# on FAT32) */
|
||
DWORD database; /* Data start sector */
|
||
DWORD fptr; /* File R/W pointer */
|
||
DWORD fsize; /* File size */
|
||
CLUST org_clust; /* File start cluster */
|
||
CLUST curr_clust; /* File current cluster */
|
||
DWORD dsect; /* File current data sector */
|
||
} FATFS;
|
||
|
||
|
||
|
||
/* Directory object structure */
|
||
|
||
typedef struct {
|
||
WORD index; /* Current read/write index number */
|
||
BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
|
||
CLUST sclust; /* Table start cluster (0:Static table) */
|
||
CLUST clust; /* Current cluster */
|
||
DWORD sect; /* Current sector */
|
||
} DIR;
|
||
|
||
|
||
|
||
/* File status structure */
|
||
|
||
typedef struct {
|
||
DWORD fsize; /* File size */
|
||
WORD fdate; /* Last modified date */
|
||
WORD ftime; /* Last modified time */
|
||
BYTE fattrib; /* Attribute */
|
||
char fname[13]; /* File name */
|
||
} FILINFO;
|
||
|
||
|
||
|
||
/* File function return code (FRESULT) */
|
||
|
||
typedef enum {
|
||
FR_OK = 0, /* 0 */
|
||
FR_DISK_ERR, /* 1 */
|
||
FR_NOT_READY, /* 2 */
|
||
FR_NO_FILE, /* 3 */
|
||
FR_NO_PATH, /* 4 */
|
||
FR_NOT_OPENED, /* 5 */
|
||
FR_NOT_ENABLED, /* 6 */
|
||
FR_NO_FILESYSTEM /* 7 */
|
||
} FRESULT;
|
||
|
||
|
||
|
||
/*--------------------------------------------------------------*/
|
||
/* Petit FatFs module application interface */
|
||
|
||
FRESULT pf_mount (FATFS*); /* Mount/Unmount a logical drive */
|
||
FRESULT pf_open (const char*); /* Open a file */
|
||
FRESULT pf_read (void*, WORD, WORD*); /* Read data from the open file */
|
||
FRESULT pf_write (const void*, WORD, WORD*); /* Write data to the open file */
|
||
FRESULT pf_lseek (DWORD); /* Move file pointer of the open file */
|
||
FRESULT pf_opendir (DIR*, const char*); /* Open a directory */
|
||
FRESULT pf_readdir (DIR*, FILINFO*); /* Read a directory item from the open directory */
|
||
|
||
|
||
|
||
/*--------------------------------------------------------------*/
|
||
/* Flags and offset address */
|
||
|
||
/* File status flag (FATFS.flag) */
|
||
|
||
#define FA_OPENED 0x01
|
||
#define FA_WPRT 0x02
|
||
#define FA__WIP 0x40
|
||
|
||
|
||
/* FAT sub type (FATFS.fs_type) */
|
||
|
||
#define FS_FAT12 1
|
||
#define FS_FAT16 2
|
||
#define FS_FAT32 3
|
||
|
||
|
||
/* File attribute bits for directory entry */
|
||
|
||
#define AM_RDO 0x01 /* Read only */
|
||
#define AM_HID 0x02 /* Hidden */
|
||
#define AM_SYS 0x04 /* System */
|
||
#define AM_VOL 0x08 /* Volume label */
|
||
#define AM_LFN 0x0F /* LFN entry */
|
||
#define AM_DIR 0x10 /* Directory */
|
||
#define AM_ARC 0x20 /* Archive */
|
||
#define AM_MASK 0x3F /* Mask of defined bits */
|
||
|
||
|
||
/*--------------------------------*/
|
||
/* Multi-byte word access macros */
|
||
|
||
#if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
|
||
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
|
||
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
|
||
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
|
||
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
|
||
#else /* Use byte-by-byte access to the FAT structure */
|
||
#define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
|
||
#define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
|
||
#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
|
||
#define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24)
|
||
#endif
|
||
|
||
|
||
#endif /* _FATFS */
|
firmware/fat/pff_file.h | ||
---|---|---|
#pragma once
|
||
|
||
#include "simplefile.h"
|
||
#include "simpledir.h"
|
||
|
||
#define MAX_DIR_LENGTH (9*5+1)
|
||
#define MAX_FILE_LENGTH (8+3+1+1)
|
||
#define MAX_PATH_LENGTH (9*5 + 8+3+1 + 1)
|
||
|
||
// Do not access these directly... They vary by architecture, just the simplefile/simpledir interface is the same
|
||
struct SimpleFile
|
||
{
|
||
char path[MAX_PATH_LENGTH];
|
||
int size;
|
||
};
|
||
|
||
struct SimpleDirEntry
|
||
{
|
||
char path[MAX_PATH_LENGTH];
|
||
char * filename_ptr;
|
||
int size;
|
||
int is_subdir;
|
||
struct SimpleDirEntry * next; // as linked list - want to allow sorting...
|
||
};
|
||
|
firmware/fileselector.h | ||
---|---|---|
#pragma once
|
||
|
||
void file_select(void (*filter) (char const *), char const * path, struct SimpleFile * file);
|
||
|
firmware/freeze.h | ||
---|---|---|
#pragma once
|
||
|
||
// Allow us to take over the system
|
||
// NB: CPU should be frozen before calling these!
|
||
|
||
// Set hardware registers to 'neutral'
|
||
// Back up system ram
|
||
void freeze();
|
||
|
||
// Restore system ram
|
||
// Restore hardware registers
|
||
void restore();
|
||
|
firmware/joystick.c | ||
---|---|---|
#include "joystick.h"
|
||
|
||
#include "regs.h"
|
||
|
||
void joystick_poll(struct joystick_status * status)
|
||
{
|
||
status->x_ = 0;
|
||
status->y_ = 0;
|
||
status->fire_ = 0;
|
||
|
||
unsigned char porta = *atari_porta;
|
||
if (0==(porta&0x2)) // down
|
||
{
|
||
status->y_ =1;
|
||
}
|
||
else if (0==(porta&0x1)) // up
|
||
{
|
||
status->y_ =-1;
|
||
}
|
||
if (0==(porta&0x8)) // right
|
||
{
|
||
status->x_ = 1;
|
||
}
|
||
else if (0==(porta&0x4)) // left
|
||
{
|
||
status->x_ = -1;
|
||
}
|
||
if (0==(1&*atari_trig0)) // fire
|
||
{
|
||
status->fire_ = 1;
|
||
}
|
||
}
|
||
|
||
void joystick_wait(struct joystick_status * status, enum JoyWait waitFor)
|
||
{
|
||
while (1)
|
||
{
|
||
joystick_poll(status);
|
||
switch (waitFor)
|
||
{
|
||
case WAIT_QUIET:
|
||
if (status->x_ == 0 && status->y_ == 0 && status->fire_ == 0) return;
|
||
break;
|
||
case WAIT_FIRE:
|
||
if (status->fire_ == 1) return;
|
||
break;
|
||
case WAIT_EITHER:
|
||
if (status->fire_ == 1) return;
|
||
// fall through
|
||
case WAIT_MOVE:
|
||
if (status->x_ != 0 || status->y_ != 0) return;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
firmware/mif_file_stuff/rom_epilogue.vhd | ||
---|---|---|
END;
|
firmware/mif_file_stuff/zpuromgen.c | ||
---|---|---|
// zpuromgen.c
|
||
//
|
||
// Program to turn a binary file into a VHDL lookup table.
|
||
// by Adam Pierce
|
||
// 29-Feb-2008
|
||
//
|
||
// This software is free to use by anyone for any purpose.
|
||
//
|
||
|
||
#include <unistd.h>
|
||
#include <stdio.h>
|
||
|
||
typedef unsigned char BYTE;
|
||
|
||
main(int argc, char **argv)
|
||
{
|
||
BYTE opcode[4];
|
||
int fd;
|
||
int addr = 0;
|
||
ssize_t s;
|
||
|
||
// Check the user has given us an input file.
|
||
if(argc < 2)
|
||
{
|
||
printf("Usage: %s <binary_file>\n\n", argv[0]);
|
||
return 1;
|
||
}
|
||
|
||
// Open the input file.
|
||
fd = open(argv[1], 0);
|
||
if(fd == -1)
|
||
{
|
||
perror("File Open");
|
||
return 2;
|
||
}
|
||
|
First cut of reworked firmware. Just runs gunpowder charlie.atr drive emulation!