memory revamp described, endianness checked
This commit is contained in:
@@ -34,6 +34,9 @@
|
||||
#define cputc(c) (putchar(c))
|
||||
#endif
|
||||
|
||||
/* also, do our best to ensure short-packed value storage in our virtual RAM */
|
||||
#pragma pack(2)
|
||||
|
||||
/* Definitions section */
|
||||
|
||||
#define EQUI_VER "0.0.1"
|
||||
@@ -312,6 +315,12 @@ ushort crc16(const uchar* data_p, uchar length) {
|
||||
return crc;
|
||||
}
|
||||
|
||||
/* Short endianness conversion helper */
|
||||
|
||||
ushort tobig(ushort val) {
|
||||
return (val>>8)|((val&255)<<8);
|
||||
}
|
||||
|
||||
/* Persistent operation handler */
|
||||
|
||||
ushort persistOp(FILE *pfd, ushort maddr, ushort dataLen, ushort adl, ushort adh, uchar isWrite) {
|
||||
@@ -587,6 +596,9 @@ void equi_main_loop() {
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
uchar instr, bc, smode = 0;
|
||||
/* detect host endianness */
|
||||
int host_islittle = 1;
|
||||
host_islittle = (*((char *)&host_islittle) == 1) ? 1 : 0;
|
||||
/* _attempt_ to disable buffering for char input/output */
|
||||
#if !defined __CC65__ && !defined __TINYC__
|
||||
setvbuf(stdin, NULL, _IONBF, 0);
|
||||
@@ -622,6 +634,15 @@ int main(int argc, char* argv[]) {
|
||||
ram.clt_start, ram.gpd_start - ram.clt_start, ram.gpd_start, ram.cmd_start - ram.gpd_start, ram.cmd_start, ram.cmd_size);
|
||||
}
|
||||
|
||||
/* now, if necessary, convert the values that could be read by the program to big-endian */
|
||||
if(host_islittle) {
|
||||
ram.stack_size = tobig(ram.stack_size);
|
||||
ram.clt_start = tobig(ram.clt_start);
|
||||
ram.gpd_start = tobig(ram.gpd_start);
|
||||
ram.cmd_start = tobig(ram.cmd_start);
|
||||
ram.cmd_size = tobig(ram.cmd_size);
|
||||
}
|
||||
|
||||
while(1) { /* Now, we're in the command mode loop */
|
||||
instr = cgetc(); /* Fetch the next instruction from the keyboard/stdin */
|
||||
if(instr == 0xFFU || instr == 0U) /* exit on zero byte */
|
||||
|
||||
Reference in New Issue
Block a user