I'd like to print some output on the 6502 simulator for testing. I've tried the following:
// GPL 2.0
#include <stdio.h>
#include <stdint.h>
void main() {
printf( "Start\n" );
printf( "End\n" );
}
#ifdef __SDCC
unsigned char __at 0x9ff0 sif; // Not sure?
int putchar(int c)
{
sif = 'p';
sif = c;
return c;
}
#endif
sdcc -mmos6502 ./print_test65.c -o print_test65.ihx && ucsim_mos6502 -I if=memory[0xe500] print_test65.ihx
uCsim 0.7.5, Copyright (C) 1997 Daniel Drotos.
0> Simif: memory is not a valid address space name
What's a valid address space name for 6502? I tried xram as well. The help says "memory", but presumably it's processor specific. Is there a list of valid address space names per processor?
Is my sif address correct/reasonable?
I do not use the 6502 port, but ports/uc6502/support.c has:
On Fri, 22 Jul 2022, Under4Mhz wrote:
6502 is pure Neumann, there is no IO space like in z80, so I think sfr
style is not usable. You shoud use a pointer, see the answer by
Philipp (and don't forget the "volatile").
Use "info mem" or "mem info" to check names of address spaces. In most
Neumann cases uCsim use "rom" as the name:
simif configuration must specify the address where the program writes
the commands, so in case of:
you have to config simif as:
Any location can be used if it is not used by the program in other
ways.
Daniel
Last edit: Maarten Brock 2022-07-22
I am totally surprised.
static unsigned char * volatile sif;Why would you want to make the pointer volatile and not the pointed to value?
Or have I totally lost touch of the rules?
Maarten
I don't know why that pointer is volatile (and I'm not very familiar with the test infrastructure and its interaction with uCSim - Daniel and Felix are the experts there).
Last edit: Philipp Klaus Krause 2022-07-22
On Fri, 22 Jul 2022, Maarten Brock wrote:
I think you are right, it is wrong and this mistake was copied to
several support.c files. Surprisingly it worked this way for years.
I've checked generated code several times in the past and
*sif=c;was never eliminated.Daniel
Yes, SDCC is lacking a good pointer analysis, and thus often won't optimize out pointer accesses where it should:
[feature-requests:#365]
Related
Feature Requests: #365
Great, thanks for your help. The following worked well:
I definitely recommend to make your sif volatile.
I don't know what writing 'p' is supposed to do, but I doubt you would want that line removed. Yet, without volatile the compiler can deduce that the 'p' value is never used and thus its assignment can be removed.