From DAR110@PSUVM.PSU.EDU Thu Apr 16 21:08:25 1992 Received: from calvin.sfasu.edu by umaxc.weeg.uiowa.edu (5.61.jnf/920125) on Thu, 16 Apr 92 21:08:17 -0500 id AA00595 with SMTP From: Received: from PSUVM.PSU.EDU ([128.118.56.2]) by calvin.sfasu.EDU with SMTP (5.59/25-eef) id AA02218; Thu, 16 Apr 92 20:45:44 CDT Return-Path: Message-Id: <9204170145.AA02218@calvin.sfasu.EDU> Received: from PSUVM.PSU.EDU by PSUVM.PSU.EDU (IBM VM SMTP V2R1) with BSMTP id 3500; Thu, 16 Apr 92 21:55:55 EDT Received: by PSUVM (Mailer R2.08) id 3218; Thu, 16 Apr 92 21:55:54 EDT Date: Thu, 16 Apr 92 21:55 EDT Subject: Inline_Assembly in H.C. 1.5 To: hyperc-l@calvin.sfasu.edu Status: R I AM LOOKING FOR FEEDBACK FROM YOU ON THE FOLLOWING MATERIAL!! Write to: dar110@psuvm.psu.edu THANKS! Methods in HyperC 1.5 -- A Creative Approach to using HyperC by WSM Group. The collection of techniques here are by Richard Wagner, and with collaboration by Andy Werner, without whose help I would not be where I am today with HyperC. Chapter XXXX: Techniques In HyperC -- In_Line Assembly A Reality! If you type in and assemble the following routine, and then append it permanately to LIBC, you will have the means to call any 65x02 routine in RAM or ROM. With this one modest routine added to LIBC, In_Line Assembly becomes a genuine reality to HyperC !! ; program to call any address! ; use to call BASIC/MONITOR ROM Routines ; self-contained, doesnt use SETUP routine ; 03/30/92 midnight #include .entry _calladr _calladr: ldy #0 lda [sp],y sta _ladr iny lda [sp],y sta _hadr .byte 0x20 ; JSR obcode _ladr: .byte 0x00 _hadr: .byte 0x00 rts ; return from call! Here it is. Perhaps for the absolute very first time (?) is an example of placing 65x02 instructions with in a HyperC program. Passing arguments to that routine, and then actually calling it, returning back to the HyperC program! /* In_Line Assembly in HyperC 1.5 ???????? routine to test inline assembly idea: 1) place 65x02 code into an unsigned char array, 2) set any values necessary in memory, 3) call the address of the character-array, 4) place a standard 65x02 RTS at the end to return to HyperC RichWagner HyperC 1.5 03/30/92 00:53 Midnight */ #include unsigned char sound[25] = { 0xa4, 0x02, /* ldy $02 */ 0xa5, 0x00, /* lda $00 */ 0x20, 0xa8, 0xfc, /* jsr $fca8 */ 0xad, 0x30, 0xc0, /* lda $c030 */ 0x88, /* dey */ 0xd0, 0xf5, /* bne ... */ 0xa5, 0x03, /* lda $03 */ 0xf0, 0x04, /* bne ... */ 0xc6, 0x03, /* dec $03 */ 0xd0, 0xed, /* bne ... */ 0x60 /* rts */ }; void main(argc,argv) int argc; char** argv; { unsigned int duration; unsigned char *hi_dur=0x03; unsigned char *lo_dur=0x02; unsigned char *freq =0x00; if (argc != 3) usage("sound "); *freq = (char)(atoi(&argv[1]) & 0xff); duration = (unsigned int)atoi(&argv[2]); *lo_dur = (char)(duration & 0xff); *hi_dur = (char)(duration >> 8); calladr(sound); } In this modest example (yes, there are a few minor mistakes in my haste to prove my point!) you actually see the declaration of a global unsigned char array. I assigned values which just happen to be genuine 65x02 obcodes! When the address of that array is given to the CALLADR routine, can you guess what happens. YEP! You call that aseembly routine! Note also: that you can SAFELY (consistantly?) place values in $00 - $07 beforehand, allowing you to PASS ARGUMENTS to your "in-line" assembly routines! This file created by Richard Wagner, and may be distributed freely! Any questions should be directed to DAR110@psuvm.psu.edu