si_prc.pp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2020 by Free Pascal development team
  4. This file contains startup code for the ZX Spectrum
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit si_prc;
  12. {$SMARTLINK OFF}
  13. {$GOTO ON}
  14. interface
  15. implementation
  16. var
  17. stktop: word; external name '__stktop';
  18. procedure PascalMain; external name 'PASCALMAIN';
  19. { this *must* always remain the first procedure with code in this unit }
  20. procedure _start; assembler; nostackframe; public name 'start';
  21. label
  22. bstart, bend, loop;
  23. asm
  24. { first init BSS }
  25. ld bc, offset bstart
  26. ld hl, offset bend
  27. scf
  28. ccf
  29. sbc hl, bc
  30. ld a, 0
  31. loop:
  32. ld (bc), a
  33. inc bc
  34. dec hl
  35. cp a, l
  36. jr NZ, loop
  37. cp a, h
  38. jr NZ, loop
  39. { now we can store the top of the stack }
  40. ld (stktop), sp
  41. jp PASCALMAIN
  42. { When using the SDCC-SDLDZ80 linker, the first object module defines the
  43. order of areas (sections). Since this module contains the startup code,
  44. it is loaded first, so we define all the sections we use in the proper
  45. order. }
  46. area '_DATA'
  47. area '_BSS'
  48. bstart:
  49. area '_BSSEND'
  50. bend:
  51. area '_HEAP'
  52. area '_STACK'
  53. area '_CODE'
  54. end;
  55. end.