mirror of
https://github.com/equant/apple2idiot.git
synced 2025-02-14 06:30:42 +00:00
cc65 weather example working
This commit is contained in:
parent
3608526101
commit
ddb8ecf415
@ -1 +0,0 @@
|
||||
Apple2Idiot
|
@ -103,7 +103,7 @@ boolean Apple2Idiot::write_data(byte address, byte byte_to_write) {
|
||||
unsigned int Apple2Idiot::write_string_to_shared_ram(String string_to_send, unsigned int address) {
|
||||
//if (string_to_send.length() > 15 - 1) { // - 1 because of null character at end of string.
|
||||
write_data(ESP_COMMAND_ADDRESS, 12);
|
||||
unsigned int c = 0;
|
||||
unsigned int c = 2;
|
||||
for (c=0; c < string_to_send.length(); c++) {
|
||||
Serial.print("A(");
|
||||
Serial.print(c);
|
||||
@ -111,19 +111,20 @@ unsigned int Apple2Idiot::write_string_to_shared_ram(String string_to_send, unsi
|
||||
Serial.println(string_to_send[c]);
|
||||
write_data(address+c, string_to_send[c]);
|
||||
}
|
||||
write_data(address+c, ETX);
|
||||
write_data(address+c, EOS);
|
||||
//write_data(15, COMMAND_FROM_ESP + command_message + COMMAND_NO_DATA_WAITING);
|
||||
write_data(ESP_COMMAND_ADDRESS, 27);
|
||||
return address+c;
|
||||
}
|
||||
|
||||
String Apple2Idiot::read_string_from_ram(int address) {
|
||||
byte c = 0;
|
||||
byte c = 2;
|
||||
int i = 0;
|
||||
String read_string = "";
|
||||
while ( (i<MAX_STR_LEN) && (c!=ETX) ) {
|
||||
while ( (i<MAX_STR_LEN) && (c!=EOS) ) {
|
||||
c = read_data(address+i);
|
||||
if (c!=ETX) {
|
||||
Serial.print("["); Serial.print(c); Serial.println("]");
|
||||
if (c!=EOS) {
|
||||
read_string = read_string + char(c);
|
||||
}
|
||||
i++;
|
||||
|
@ -37,7 +37,9 @@
|
||||
#define RW_WRITE LOW
|
||||
#define RW_READ HIGH
|
||||
|
||||
#define ETX 3 // ASCII "End of Text" (ETX) character
|
||||
// Deprecated ETX. Use NULL terminated strings now.
|
||||
//#define ETX 0 // ASCII "End of Text" (ETX) character
|
||||
#define EOS 0
|
||||
|
||||
#define INPUT_35 35
|
||||
#define INPUT_34 34
|
||||
|
@ -53,7 +53,8 @@ byte address_pins[] = {A0R, A1R, A2R, A3R, A4R, A5R, A6R, A7R};
|
||||
#define INPUT_35 35
|
||||
#define INPUT_34 34
|
||||
|
||||
#define ETX 3 // ASCII "End of Text" (ETX) character
|
||||
// deprecated. use NULL
|
||||
//#define ETX 3 // ASCII "End of Text" (ETX) character
|
||||
#define ACK 0b00000110 // Acknowledge
|
||||
#define EOT 0b00000100 // End of transmit
|
||||
|
||||
@ -147,7 +148,7 @@ void send_string_to_apple(String string_to_send, int address) {
|
||||
Serial.println(string_to_send[c]);
|
||||
write_data(address+c, string_to_send[c]);
|
||||
}
|
||||
write_data(address+c, ETX);
|
||||
write_data(address+c, NULL);
|
||||
//write_data(15, COMMAND_FROM_ESP + command_message + COMMAND_NO_DATA_WAITING);
|
||||
write_data(ESP_COMMAND_ADDRESS, 27);
|
||||
}
|
||||
@ -156,7 +157,7 @@ String read_string_from_ram(int address) {
|
||||
byte c = 0;
|
||||
int i = 0;
|
||||
String read_string = "";
|
||||
while ( (i<MAX_STR_LEN) && (c!=ETX) ) {
|
||||
while ( (i<MAX_STR_LEN) && (c!=NULL) ) {
|
||||
c = read_data(address+i);
|
||||
read_string = read_string + char(c);
|
||||
i++;
|
||||
|
@ -2,3 +2,4 @@
|
||||
make
|
||||
make TARGETS=apple2 dsk
|
||||
```
|
||||
cp weather.dsk ~/bin/ADTPro-2.1.0/disks/
|
||||
|
Binary file not shown.
BIN
examples/weather/apple2-cc65/apple2/template.dsk.plain
Normal file
BIN
examples/weather/apple2-cc65/apple2/template.dsk.plain
Normal file
Binary file not shown.
BIN
examples/weather/apple2-cc65/apple2/template.dsk.with_utils
Normal file
BIN
examples/weather/apple2-cc65/apple2/template.dsk.with_utils
Normal file
Binary file not shown.
@ -1 +1,2 @@
|
||||
cl65 -t apple2 weather.c -o weather
|
||||
cp weather.dsk ~/bin/ADTPro-2.1.0/disks/
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -6,44 +6,47 @@
|
||||
#include "globals.h"
|
||||
#include "apple2idiot.h"
|
||||
|
||||
unsigned char read_data(unsigned char address) {
|
||||
#define MAX_STR_LEN 250
|
||||
|
||||
|
||||
unsigned char read_byte(unsigned int address) {
|
||||
gotoxy(0,2);
|
||||
printf("read_data()");
|
||||
//printf("read_data(%u)", address);
|
||||
}
|
||||
|
||||
unsigned char write_data(unsigned char address, unsigned char byte_to_write) {
|
||||
printf("%d [%c]\n", address, byte_to_write);
|
||||
unsigned char write_byte(unsigned int address, unsigned char byte_to_write) {
|
||||
//printf("%u <- %d, [%c]\n", address, byte_to_write, byte_to_write);
|
||||
POKE(address, byte_to_write);
|
||||
//for (i=0;i<8;i++)
|
||||
//{
|
||||
//p = PEEK(0xC200+i);
|
||||
//printf("(%u) -> %d, %c\n", 0xC200+i, p, p);
|
||||
//}
|
||||
//cursor(1);
|
||||
//p = cgetc();
|
||||
//gotoxy(0, SIZE_Y-5);
|
||||
//printf("You said: %c\n", p);
|
||||
}
|
||||
|
||||
unsigned char* write_string_to_ram(char* string_to_send, unsigned char address) {
|
||||
unsigned char i, p, c;
|
||||
unsigned char* write_string_to_ram(unsigned int address, char* string_to_send) {
|
||||
unsigned char i;
|
||||
unsigned char size = strlen(string_to_send);
|
||||
gotoxy(0,2);
|
||||
if (string_to_send[size-1] == '\n') {
|
||||
string_to_send[size-1] = 0;
|
||||
string_to_send[size-1] = '\0';
|
||||
}
|
||||
//printf("write_string_to_ram()");
|
||||
//printf("%u (%s)\n", address, string_to_send);
|
||||
for (i=0; i<size; i++) {
|
||||
write_data(address+i, string_to_send[i]);
|
||||
write_byte(address+i, string_to_send[i]);
|
||||
}
|
||||
if (string_to_send[size-1] != 0) {
|
||||
write_data(address+i, 0);
|
||||
if (string_to_send[size-1] != '\0') {
|
||||
write_byte(address+i, '\0');
|
||||
}
|
||||
gotoxy(0,9);
|
||||
p = cgetc();
|
||||
}
|
||||
|
||||
unsigned char* read_string_from_ram(char* string_to_send, unsigned char address) {
|
||||
// HOW DO I PASS THE ADDRESS TO read_string_from_ram ???
|
||||
|
||||
void read_string_from_ram(unsigned int address, char *data, char length) {
|
||||
unsigned char c, i;
|
||||
gotoxy(0,2);
|
||||
printf("read_string_from_ram()");
|
||||
//printf("A: %u, L: %c\n", address, length);
|
||||
//cgetc();
|
||||
for (i=0; i<length; i++) {
|
||||
c = PEEK(address + i);
|
||||
data[i] = c;
|
||||
if (c == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
#ifndef _A2I_H
|
||||
#define _A2I_H
|
||||
|
||||
|
||||
unsigned char read_data(unsigned char address);
|
||||
unsigned char write_data(unsigned char address, unsigned char byte_to_write);
|
||||
unsigned char* write_string_to_ram(char* string_to_send, unsigned char address);
|
||||
unsigned char* read_string_from_ram(char* string_to_send, unsigned char address);
|
||||
unsigned char read_byte(unsigned int address);
|
||||
unsigned char write_byte(unsigned int address, unsigned char byte_to_write);
|
||||
unsigned char* write_string_to_ram(unsigned int address, char* string_to_send);
|
||||
void read_string_from_ram(unsigned int address, char *data, char length);
|
||||
|
||||
#endif
|
||||
|
@ -6,10 +6,15 @@
|
||||
#define ASCII_2 50
|
||||
#define ASCII_3 51
|
||||
#define ASCII_4 52
|
||||
#define ASCII_5 53
|
||||
|
||||
#define SIZE_X 40
|
||||
#define SIZE_Y 24
|
||||
|
||||
#define CARD_ADDRESS 0xC200
|
||||
#define APPLE_COMMAND_ADDRESS 0xC201
|
||||
#define RAM_DATA_START_ADDRESS 0xC202
|
||||
|
||||
#define COMMAND_SET_COUNTRY 200
|
||||
#define COMMAND_SET_CITY 201
|
||||
#define COMMAND_FETCH_WEATHER 205
|
||||
|
@ -1,58 +1,102 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <conio.h>
|
||||
#include <ctype.h>
|
||||
#include <apple2.h>
|
||||
#include <peekpoke.h>
|
||||
|
||||
#include "globals.h"
|
||||
#include "menu.h"
|
||||
#include "apple2idiot.h"
|
||||
|
||||
unsigned char i = 0;
|
||||
char p;
|
||||
char text[20];
|
||||
|
||||
char pause_char;
|
||||
char city[33];
|
||||
char country_code[3];
|
||||
char temperature[7];
|
||||
char humidity[7];
|
||||
char wind_speed[7];
|
||||
char wind_direction[5];
|
||||
char weather1[250];
|
||||
char weather2[250];
|
||||
unsigned int address_offset = 0;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
unsigned char key;
|
||||
|
||||
while (key != ASCII_0) { // Last menu item should be Quit
|
||||
clrscr();
|
||||
|
||||
while (key != ASCII_5) { // Last menu item should be Quit
|
||||
drawMenuBar();
|
||||
//cvlinexy(0,1,size_x);
|
||||
//fancy_hline(0,2);
|
||||
//fputs("enter some text: ", stdout);
|
||||
//fflush(stdout); /* http://c-faq.com/stdio/fflush.html */
|
||||
//fgets(text, sizeof text, stdin);
|
||||
//printf("\ntext = \"%s\"", text);
|
||||
//revers(1);
|
||||
gotoxy(0,2);
|
||||
printf("Country: %s City:%s", country_code, city);
|
||||
gotoxy(0,SIZE_Y-1);
|
||||
printf("Selection:");
|
||||
printf("Menu Selection:");
|
||||
cursor(1);
|
||||
//revers(0);
|
||||
//p = cgetc();
|
||||
key = toupper(cgetc());
|
||||
gotoxy(0,SIZE_Y-3);
|
||||
printf("cgetc() -> \"%c\"", key);
|
||||
//printf("cgetc() -> \"%c\"", key);
|
||||
|
||||
switch((int)key) {
|
||||
case ASCII_0:
|
||||
printf("QUIT!");
|
||||
break;
|
||||
case ASCII_5:
|
||||
break;
|
||||
case ASCII_1:
|
||||
printf("COUNTRY!");
|
||||
write_string_to_ram("US", 0xC202);
|
||||
clrscr();
|
||||
drawMenuBar();
|
||||
gotoxy(0,SIZE_Y-1);
|
||||
printf("Enter Country Code:");
|
||||
fgets(country_code, sizeof country_code, stdin);
|
||||
strncpy(country_code, country_code, strlen(country_code));
|
||||
//country_code[strcspn(country_code, "\n")] = 0;
|
||||
write_string_to_ram(RAM_DATA_START_ADDRESS, country_code);
|
||||
write_byte(APPLE_COMMAND_ADDRESS, COMMAND_SET_COUNTRY);
|
||||
//printf("C:[%s]", country_code);
|
||||
//pause_char = cgetc();
|
||||
break;
|
||||
case ASCII_2:
|
||||
printf("City: ");
|
||||
fgets(text, sizeof text, stdin);
|
||||
write_string_to_ram(text, 0xC202);
|
||||
clrscr();
|
||||
drawMenuBar();
|
||||
gotoxy(0,SIZE_Y-1);
|
||||
printf("Enter City: ");
|
||||
fgets(city, sizeof city, stdin);
|
||||
city[strcspn(city, "\n")] = 0;
|
||||
write_string_to_ram(RAM_DATA_START_ADDRESS, city);
|
||||
write_byte(APPLE_COMMAND_ADDRESS, COMMAND_SET_CITY);
|
||||
//printf("C:[%s]", city);
|
||||
//pause_char = cgetc();
|
||||
break;
|
||||
case ASCII_3:
|
||||
printf("UPDATE!");
|
||||
clrscr();
|
||||
drawMenuBar();
|
||||
write_byte(APPLE_COMMAND_ADDRESS, COMMAND_FETCH_WEATHER);
|
||||
break;
|
||||
case ASCII_4:
|
||||
clrscr();
|
||||
drawMenuBar();
|
||||
read_string_from_ram(RAM_DATA_START_ADDRESS + address_offset, temperature, sizeof temperature-1);
|
||||
address_offset += strlen(temperature) + 1;
|
||||
read_string_from_ram(RAM_DATA_START_ADDRESS + address_offset, humidity, sizeof humidity-1);
|
||||
address_offset += strlen(humidity) + 1;
|
||||
read_string_from_ram(RAM_DATA_START_ADDRESS + address_offset, wind_speed, sizeof wind_speed-1);
|
||||
address_offset += strlen(wind_speed) + 1;
|
||||
read_string_from_ram(RAM_DATA_START_ADDRESS + address_offset, wind_direction, sizeof wind_direction-1);
|
||||
address_offset += strlen(wind_direction) + 1;
|
||||
read_string_from_ram(RAM_DATA_START_ADDRESS + address_offset, weather1, sizeof weather1-1);
|
||||
address_offset += strlen(weather1) + 1;
|
||||
read_string_from_ram(RAM_DATA_START_ADDRESS + address_offset, weather2, sizeof weather2-1);
|
||||
gotoxy(0,SIZE_Y-11);
|
||||
printf("%s (%s)\n", city, country_code);
|
||||
printf("-------------------------------------\n");
|
||||
printf("Temp: %s K\n", temperature);
|
||||
printf("Humidity: %s%%\n", humidity);
|
||||
printf("Wind Speed: %s m/s\n", wind_speed);
|
||||
printf("Wind Dir: %s \n", wind_direction);
|
||||
printf("Summary: %s, %s \n", weather1, weather2);
|
||||
printf("-------------------------------------\n");
|
||||
break;
|
||||
default:
|
||||
printf("DEFAULT!");
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -6,9 +6,9 @@
|
||||
#include "globals.h"
|
||||
#include "menu.h"
|
||||
|
||||
#define MENU_LENGTH 4
|
||||
#define MENU_LENGTH 5
|
||||
#define MENU_WORD_LENGTH 8
|
||||
unsigned char menuEntries[MENU_LENGTH][MENU_WORD_LENGTH] = {"Country", "City", "Update", "Quit"};
|
||||
unsigned char menuEntries[MENU_LENGTH][MENU_WORD_LENGTH] = {"Country", "City", "Fetch", "Display", "Quit"};
|
||||
|
||||
void drawMenuBar() {
|
||||
static unsigned char i;
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user