Oberon and assembler
Interfacing with assembler
Passing parameters
Passing parameters in registers to SDCC
not implemented, although Philipp Krause promised
think about it. Parameters for re─ functions
are given on the stack, the top address is stored
gate. There are several ways to get pa─
dimensions, and you need to choose the most
acceptable. If the parameter(s) occupies
1 or 2 bytes, then the following code would be good:
POP HL; Return address
POP BC; One-byte parameter ─ in C,
PUSH BC; and if double-byte, then in BC
PUSH HL; If the HL procedure does not
; spoils, you can replace it
; PUSH HL:RET on JP (HL)
Or like this (count the clock cycles and bytes yourself):
LD HL,#2
ADD HL,SP
LD C,(HL); 1st byte of parameter(s)
INC HL
LD B,(HL); 2nd byte of parameter(s)
If deep in the body of the subroutine it is required
getting parameters in arbitraryorder─
ke, then perhaps it would be more optimal
address parameters viaIX:
PUSH IX
LD IX,#0
ADD IX,SP
LD C,4(IX); 1st byte of parameter(s)
LD B,5(IX); 2nd byte of parameter(s)
...
POP IX
A function should not retrieve its parameters
from the stack completely, ─ in the mental call model─
Finally, the compiler itself extracts the parameters
after returning from the function (which in some cases
cases helps him optimize the code).
Also, the function should not destroy the content─
my registerIX, through which SDCC works─
melts with local variables.
Result of functions depending on time─
the measure is returned in registerL, in the HL pair
or inDE:HL.
Efficient Z80 code view,
suitable for porting
Let us touch upon such an interesting question as
porting Spectrum games to other boards─
forms.It's no secret that assembly code is not
too visual, but too voluminous.
And to clarify his logic, come often─
I’m trying to analyze huge pieces in great detail─
ki code, trying to understand and describe what they
do. The results of such painstaking work─
it's not a sin to document by rewriting
to a higher level language, and here we
XDev can help, which provides
the language is simple enough to be expanded─
noisy on other platforms, but also enough
modern conceptually, because, despite
almost 30 years old, great lo─
lives on almost all modern apps─
military and software platforms that I demo─
illustrated with examples of midlets onOberon
(http://zx.oberon2.ru/forum/
viewtopic.php?f=27&t=38 )
and even some progress in development
for Android
(http://zx.oberon2.ru/forum/
viewtopic.php?f=87&t=244 ).
But, for example,C, as far as I know─
it is known, it cannot be translated into bytecode
Dalvik and in Java .classes, because C has
too many dangerous possibilities, fromco─
which they tried to get rid of in Java machines─
at the bytecode level. The same thing is possible
say about browser applications.Oberon
it fits perfectly even with microcontrol─
lers
(http://www.youtube.com/
watch?v=zlnjбFCY1tY ),
not to mentionJVM and .NET
(http://gpcp.codeplex.com ).
Unfortunately, the journal article format is not
allows you to describe processes in detail─
Z80-code radios for other platforms, but if
Are you wondering what inter─
library faces and application code, transli─
can be packaged in different (very different!) containers─
gety, then look at the XDev environment (and its subsystem
themes for development for different platforms)
and Monkey X environment(http://monkey-x.ru), co─
which also offers broadcasting from one
language for different targets, which when
all the shortcomings of the implementation (it is far from
universality, but everything needs to be developed)
saves time and resources, which are against─
otherwise they would spend money on studying ten─
tkov (rapidly changing) languages, platforms and
their API.
I would also like to note that I have not seen
no satisfactory solution forinstant development for Speck and others─
different platforms. You may argue that neither─
who is not interested in crossing Speck with PC.
I can answer in response ─ why?
the same program or game must be
written differently for different platforms? And
especially in different languages, which are now
like uncut dogs. I get tired of being surprised when
I just read new language names. Not
is there a problem here that you are not
did you notice?
So why don’t I thinkSi is so good─
a powerful tool for one-step development
tka. Firstly, see above about howSi lo─
lives on modern platforms, or rather,
no longer goes to bed. Secondly, look no─
a biased view of the source code of any game─
Ruska for Spectrum, written inC[well,
not counting games on the Churrera engine -Ed.].
Have you not paid attention to the abundance before?
inserts on ACMA? So, I assure you: this is
sentence. Although it’s nice that it’s not entirely
everything is on ASMA. In general, I haven’t seen a single Wednesday─
development methods, with the help of which success─
I would like to at least partially automate
the process of pulling the game out of the framework of the spectrum─
room restrictions. Everything needs to be rewritten
again. XDev is also not such a medium─
yours, butOberon as a language with all its rigidity
its frame and abundance of restrictions ─ in volume─
this is a good basis for multi-targeting
development, it seems to me. But it's coming
studying its capabilities in this regard and,
of course, their improvement. It's important
Please understand that I am not offering a panacea, just
I identify the problem and encourage you to look for ways
her solutions, if you're interested.
We are migrating from Z80-ASMA toC, but not
having found in it sufficient support for the butt─
high-level programming ─
a safe, visual tool for prog─
ramm with a complex structure and meta-program─
miming (scripting)
(http://forum.oberoncore.ru/
viewtopic.php?f=6&t=5267 ),
staying within the scope of the compiled code, we
we move on to Oberon, but leave behind
is an opportunity to use for a low level
and asm, andC, and Java, if necessary (by─
the latter is not for ZX, of course, but for Java-based
platforms). That's why I see languageC in
application to other platforms as ASMA
Z80 for Spec. Good for low level,
but it starts to irritate me when work is going on
with complex applicationlogic.
Considering that the code on the Z80 is good
I would like to attach a convenient and unambiguously appropriate answer─
code in the language corresponding to the logic of Asmov
high level, and most importantly ─ compiled
and executable (and ideally ─ also cross─
platform!), leaving out mention─
knowledge of many compatibility issues and
differences in libraries, interfaces and more
a lot of things, I’ll just show you how you can benefit─
Look at the code that implements the game for the Spectrum/
Z80 and other platforms at the same time, completely
without claiming, by the way, that XDev is ideal
environment for these applications (at this point
Asmers shout “Mazday” and fight in paroxy─
the scope of YaVU-hatred as applied to
Spectrum).
So, here is the procedure for polling the keyboard from
games "Fool" from CopperFeet, ported
onOberon with Laser Basic, and then additional─
an alternative implementation on the accessory─
mbler:
MODULE Durak;
IMPORT M := Asm, B := Basic, Cfg;
TYPE KeyCode = CHAR; VAR time: INTEGER;
(* Scan keys & return a control code: *)
PROCEDURE GetKey (): KeyCode;
BEGIN
IF Cfg.Oberon THEN
(* ~ 2 min 50 sec to play music: *)
DEC(time, 9); B.PAUSE(9);
(* <Y>, <U>, <I>, <O>, <P>: *)
IF BITS(B.PORTIN(ODFFEH))*BITS(1FH)
# BITS(1FH) THEN RETURN 2X END;
(* <Q>, <W>, <E>, <R>, <T>: *)
IF BITS(B.PORTIN(OFBFEH))*BITS(1FH)
# BITS(1FH) THEN RETURN 1X END;
(* <A>, <S>, <D>, <F>, <G>: *)
IF BITS(B.PORTIN(OFDFEH))*BITS(1FH)
# BITS(1FH) THEN RETURN 3X END;
(* <H>, <J>, <K>, <L>, <Enter>: *)
IF BITS(B.PORTIN(OBFFEH))*BITS(1FH)
# BITS(1FH) THEN RETURN 4X END;
(* <B>, <N>, <M>, <SS>, <Space>: *)
IF BITS(B.PORTIN( 7FFEH))*BITS(1FH)
# BITS(1FH) THEN RETURN 5X END;
ELSE
(* DEC(time, 9): *)
M.Code("LD HL, (_Durak_time) ");
M.Code("LD DE, #0-9 ");
M.Code("ADD HL, DE ");
M.Code("LD (_Durak_time), HL ");
(* B.PAUSE(9): *)
M.Code("LD HL, #9 ");
M.Code("PUSH HL ");
M.Code("CALL _Basic_PAUSE_DI_stdcall");
(* <Y>, <U>, <I>, <O>, <P>: *)
M.Code("LD BC, #OxDFFE ");
M.Code("IN A, (C) ");
M.Code("CPL ");
M.Code("AND #0x1F ");
M.Code("LD L, #2 ");
M.Code("RET Z ");
(* <Q>, <W>, <E>, <R>, <T>: *)
M.Code("DEC L ");
M.Code("LD BC, #OxFBFE ");
M.Code("IN A, (C) ");
M.Code("CPL ");
M.Code("AND #0x1F ");
M.Code("RET Z ");
(* <A>, <S>, <D>, <F>, <G>: *)
M.Code("LD BC,#OxFDFE ");
M.Code("IN A, (C) ");
M.Code("CPL ");
M.Code("AND #0x1F ");
M.Code("LD L, #3 ");
M.Code("RET Z ");
(* <H>, <J>, <K>, <L>, <Enter>: *)
M.Code("INC L ");
M.Code("LD BC, #OxBFFE ");
M.Code("IN A, (C) ");
M.Code("CPL ");
M.Code("AND #0x1F ");
M.Code("RET Z ");
(* <B>, <N>, <M>, <SS>, <Space>: *)
M.Code("INC L ");
M.Code("LD BC, #0x7FFE ");
M.Code("IN A, (C) ");
M.Code("CPL ");
M.Code("AND #0x1F ");
M.Code("RET Z ");
END;
RETURN 0X
END GetKey;
END Durak.
Interestingly, Asmov code, of course,
more compact, but if you compress this thing with Hrum,
then the result is a compressed Oberonian reality─
tion is smaller in size than the compressed asmov─
sky. Which allows us to draw a bold conclusion:
with enough memory and speed
action in case of loading machine code─
yes, in an already compressed form (and at a reasonable speed─
unpacking growth) all that remains is to save
address space, which in this case─
tea and is the main resource for eco─
nomies and the most powerful argument for asm-
implementation in case of insufficiency,
whereas for some problems it is more important
It’s not so much simple to have targeted savings─
war, how much greater simplicity and destruction─
development bone (layout, prototypes─
tion, debugging tools, etc.). [Vpro─
than,we can use interpreted
pi code to save address space─
va, having lost in speed -Ed.]
Opportunities of Oberon languages,
missing from ZXDev
There are a number ofOberon capabilities that
are unlikely to ever be implemented for
development for the Z80 processor. This is dynamic─
cheskayamodularity (loading/unloading mo─
bullets "on the fly"), automatic control
memory (garbage collection; but use
dynamic memory is still possible, obviously
releasing it usingPlatform.DISPOSE),
kernel meta-programming capabilities,
exception handling, instantaneous (by─
mortal) debugging, etc. As you understand,
speed and memory (especially address pro─
travel) Z80 is clearly not enough to
fully feel the beauty of the time─
boots in Oberon languages.
Share your thoughts about the article